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