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