]> Sergey Matveev's repositories - godlighty.git/blob - rc/git.go
Initial commit
[godlighty.git] / rc / git.go
1 package rc
2
3 import (
4         "net/http"
5         "net/http/cgi"
6
7         "go.stargrave.org/godlighty"
8 )
9
10 func addGitRepoCfg(host, root, gitwebCfg string) {
11         godlighty.Hosts[host] = &godlighty.HostCfg{
12                 TLS: newTLSCfg(host),
13                 Hooks: []godlighty.Hook{
14                         func(w http.ResponseWriter, r *http.Request) bool {
15                                 if r.URL.Path == "/" {
16                                         http.Redirect(w, r, "//"+host+"/", http.StatusMovedPermanently)
17                                         return true
18                                 }
19                                 return false
20                         },
21                         func(w http.ResponseWriter, r *http.Request) bool {
22                                 runCGIAndLog(host, w, r, &cgi.Handler{
23                                         Path: "/usr/local/libexec/git-core/git-http-backend",
24                                         Dir:  "/var/empty",
25                                         Env: []string{
26                                                 "GIT_PROJECT_ROOT=" + root,
27                                                 "GIT_HTTP_EXPORT_ALL=",
28                                         },
29                                 })
30                                 return true
31                         },
32                 },
33         }
34         host = "www." + host
35         godlighty.Hosts[host] = &godlighty.HostCfg{
36                 Root: "/usr/local/share/gitweb",
37                 TLS:  newTLSCfg(host),
38                 Hooks: []godlighty.Hook{
39                         func(w http.ResponseWriter, r *http.Request) bool {
40                                 if r.URL.Path == "/" {
41                                         runCGIAndLog(host, w, r, &cgi.Handler{
42                                                 Path: "/usr/local/share/gitweb/gitweb.cgi",
43                                                 Env:  []string{"GITWEB_CONFIG=" + gitwebCfg},
44                                         })
45                                         return true
46                                 }
47                                 return false
48                         },
49                 },
50         }
51 }
52
53 func init() {
54         addGitRepoCfg("git.stargrave.org", "/home/git/pub", "/home/git/stargrave.org.conf")
55 }