-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.12 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
package main
import (
"code.google.com/p/gorilla/mux"
"net/http"
"os"
)
type globalContext struct {
kantan_root string
}
type requestContext struct {
globalContext
vars map[string]string
Project Project
}
type requestHandler struct {
globalContext
f func(requestContext, http.ResponseWriter, *http.Request)
}
func (handler *requestHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
rCtx := requestContext{
globalContext: globalContext{
kantan_root: handler.globalContext.kantan_root,
},
vars: vars,
Project: NewProject(handler.globalContext.kantan_root, vars["project"]),
}
handler.f(rCtx, w, req)
}
func main() {
kantan_root, _ := os.Getwd()
if env_kantan_root := os.Getenv("KANTAN_ROOT"); env_kantan_root != "" {
kantan_root = env_kantan_root
}
r := mux.NewRouter()
ctx := globalContext{kantan_root}
r.Path("/projects/{project}/repo/git-receive-pack").Handler(&requestHandler{ctx, requestContext.projRepoReceivePackHandler})
r.PathPrefix("/projects/{project}/repo").Handler(&requestHandler{ctx, requestContext.projRepoHandler})
http.ListenAndServe(":9090", r)
}