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
59
60
61
62
|
package main
import (
"net/http"
)
func createRepo(w http.ResponseWriter, r *http.Request) {
/*
cmd := exec.Command(g.GitBinPath, args...)
cmd.Dir = dir
stdin, err := cmd.StdinPipe()
*/
w.Write([]byte("This is my home page"))
}
/*
func CustomAuthenticator(authf func(info auth.AuthInfo) (bool, error)) func(http.Handler) http.Handler {
return func(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
auth, err := parseAuthHeader(req.Header.Get("Authorization"))
if err != nil {
w.Header().Set("WWW-Authenticate", `Basic realm="git server"`)
http.Error(w, err.Error(), 401)
return
}
// Build up info from request headers and URL
info := AuthInfo{
Username: auth.Name,
Password: auth.Pass,
Repo: repoName(req.URL.Path),
Push: isPush(req),
Fetch: isFetch(req),
}
// Call authentication function
authenticated, err := authf(info)
if err != nil {
code := 500
msg := err.Error()
if se, ok := err.(StatusError); ok {
code = se.StatusCode()
}
http.Error(w, msg, code)
return
}
// Deny access to repo
if !authenticated {
http.Error(w, "Forbidden", 403)
return
}
// Access granted
handler.ServeHTTP(w, req)
})
}
}
*/
|