+3
-3
cmd/knotserver/main.go
+3
-3
cmd/knotserver/main.go
···
10
11
"github.com/icyphox/bild/config"
12
"github.com/icyphox/bild/db"
13
-
"github.com/icyphox/bild/routes"
14
)
15
16
func main() {
···
29
log.Fatalf("failed to setup db: %s", err)
30
}
31
32
-
mux, err := routes.Setup(c, db)
33
if err != nil {
34
log.Fatal(err)
35
}
···
37
addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
38
39
log.Println("starting main server on", addr)
40
-
go http.ListenAndServe(addr, mux)
41
}
···
10
11
"github.com/icyphox/bild/config"
12
"github.com/icyphox/bild/db"
13
+
"github.com/icyphox/bild/knotserver"
14
)
15
16
func main() {
···
29
log.Fatalf("failed to setup db: %s", err)
30
}
31
32
+
mux, err := knotserver.Setup(c, db)
33
if err != nil {
34
log.Fatal(err)
35
}
···
37
addr := fmt.Sprintf("%s:%d", c.Server.Host, c.Server.Port)
38
39
log.Println("starting main server on", addr)
40
+
log.Fatal(http.ListenAndServe(addr, mux))
41
}
-1
go.mod
-1
go.mod
-2
go.sum
-2
go.sum
···
53
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
54
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
55
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
56
-
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
57
-
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
58
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
59
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
60
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
···
53
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
54
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
55
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
56
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
57
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
58
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
+8
-8
knotserver/git.go
+8
-8
knotserver/git.go
···
7
"net/http"
8
"path/filepath"
9
10
"github.com/icyphox/bild/knotserver/git/service"
11
)
12
func (d *Handle) InfoRefs(w http.ResponseWriter, r *http.Request) {
13
-
name := displayRepoName(r)
14
-
name = filepath.Clean(name)
15
-
16
-
repo := filepath.Join(d.c.Repo.ScanPath, name)
17
18
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
19
w.WriteHeader(http.StatusOK)
···
31
}
32
33
func (d *Handle) UploadPack(w http.ResponseWriter, r *http.Request) {
34
-
name := displayRepoName(r)
35
-
name = filepath.Clean(name)
36
-
37
-
repo := filepath.Join(d.c.Repo.ScanPath, name)
38
39
w.Header().Set("content-type", "application/x-git-upload-pack-result")
40
w.Header().Set("Connection", "Keep-Alive")
···
7
"net/http"
8
"path/filepath"
9
10
+
"github.com/go-chi/chi/v5"
11
"github.com/icyphox/bild/knotserver/git/service"
12
)
13
+
14
func (d *Handle) InfoRefs(w http.ResponseWriter, r *http.Request) {
15
+
did := chi.URLParam(r, "did")
16
+
name := chi.URLParam(r, "name")
17
+
repo := filepath.Join(d.c.Repo.ScanPath, did, name)
18
19
w.Header().Set("content-type", "application/x-git-upload-pack-advertisement")
20
w.WriteHeader(http.StatusOK)
···
32
}
33
34
func (d *Handle) UploadPack(w http.ResponseWriter, r *http.Request) {
35
+
did := chi.URLParam(r, "did")
36
+
name := chi.URLParam(r, "name")
37
+
repo := filepath.Join(d.c.Repo.ScanPath, did, name)
38
39
w.Header().Set("content-type", "application/x-git-upload-pack-result")
40
w.Header().Set("Connection", "Keep-Alive")
+9
-9
knotserver/handler.go
+9
-9
knotserver/handler.go
···
1
package knotserver
2
3
import (
4
"net/http"
5
6
-
"github.com/go-chi/chi"
7
"github.com/icyphox/bild/config"
8
"github.com/icyphox/bild/db"
9
)
···
22
// r.Put("/new", h.NewRepo)
23
// })
24
25
r.Route("/{did}", func(r chi.Router) {
26
-
r.Get("/", h.Index)
27
-
28
// Repo routes
29
r.Route("/{name}", func(r chi.Router) {
30
-
r.Get("/", h.Multiplex)
31
-
r.Post("/", h.Multiplex)
32
33
r.Route("/tree/{ref}", func(r chi.Router) {
34
r.Get("/*", h.RepoTree)
···
42
r.Get("/archive/{file}", h.Archive)
43
r.Get("/commit/{ref}", h.Diff)
44
r.Get("/refs/", h.Refs)
45
-
46
-
// Catch-all routes
47
-
r.Get("/*", h.Multiplex)
48
-
r.Post("/*", h.Multiplex)
49
})
50
})
51
···
65
w.Write([]byte("no pushing allowed!"))
66
return
67
}
68
69
if path == "info/refs" &&
70
r.URL.RawQuery == "service=git-upload-pack" &&
···
1
package knotserver
2
3
import (
4
+
"fmt"
5
"net/http"
6
7
+
"github.com/go-chi/chi/v5"
8
"github.com/icyphox/bild/config"
9
"github.com/icyphox/bild/db"
10
)
···
23
// r.Put("/new", h.NewRepo)
24
// })
25
26
+
r.Get("/", h.Index)
27
r.Route("/{did}", func(r chi.Router) {
28
// Repo routes
29
r.Route("/{name}", func(r chi.Router) {
30
+
r.Get("/", h.RepoIndex)
31
+
r.Get("/info/refs", h.InfoRefs)
32
+
r.Post("/git-upload-pack", h.UploadPack)
33
34
r.Route("/tree/{ref}", func(r chi.Router) {
35
r.Get("/*", h.RepoTree)
···
43
r.Get("/archive/{file}", h.Archive)
44
r.Get("/commit/{ref}", h.Diff)
45
r.Get("/refs/", h.Refs)
46
})
47
})
48
···
62
w.Write([]byte("no pushing allowed!"))
63
return
64
}
65
+
66
+
fmt.Println(r.URL.RawQuery)
67
+
fmt.Println(r.Method)
68
69
if path == "info/refs" &&
70
r.URL.RawQuery == "service=git-upload-pack" &&
+1
-1
knotserver/http_util.go
+1
-1
knotserver/http_util.go
+2
knotserver/routes.go
+2
knotserver/routes.go
···
30
writeMsg(w, "repo empty")
31
return
32
} else {
33
+
log.Println(err)
34
notFound(w)
35
return
36
}
···
202
}
203
204
func (h *Handle) Log(w http.ResponseWriter, r *http.Request) {
205
+
fmt.Println(r.URL.Path)
206
ref := chi.URLParam(r, "ref")
207
208
path := filepath.Join(h.c.Repo.ScanPath, didPath(r))
+4
-2
knotserver/util.go
+4
-2
knotserver/util.go