-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmain.go
58 lines (45 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"log"
"net/http"
"path/filepath"
"strconv"
assetfs "github.com/elazarl/go-bindata-assetfs"
_ "net/http/pprof"
"github.com/lucas-clemente/goldfish/git"
"github.com/lucas-clemente/goldfish/server"
)
func main() {
var port int
flag.IntVar(&port, "p", 3456, "tcp port to listen on")
flag.Parse()
if flag.NArg() != 1 {
log.Fatal("Usage: ./goldfish <path/to/repo>")
}
path := flag.Arg(0)
path, err := filepath.EvalSymlinks(path)
if err != nil {
log.Fatal(err)
}
path, err = filepath.Abs(path)
if err != nil {
log.Fatal(err)
}
repo, err := git.NewGitRepo(path)
if err != nil {
log.Fatal(err)
}
fmt.Printf("🐟 Goldfish listening on http://localhost:%d\n", port)
http.Handle("/v2/", server.NewHandler2(repo))
http.Handle("/assets/", http.FileServer(&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir}))
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
index, err := Asset("index.html")
if err != nil {
panic("could not find index.html")
}
w.Write(index)
})
log.Fatal(http.ListenAndServe("localhost:"+strconv.Itoa(port), nil))
}