]> Sergey Matveev's repositories - godlighty.git/blob - doc/cfg.texi
79b3d057e4b6d02e04e67b0c423bc04ea4cef017
[godlighty.git] / doc / cfg.texi
1 @node Configuration
2 @unnumbered Configuration
3
4 Initially @command{godlighty} has basic static files handlers (with
5 compression, HTTP preconditions are enabled of course). In the example
6 below there are nearly all default functions.
7 Also look for @file{rc/example.cfg}.
8
9 @verbatim
10 Hosts["example.com"] = &godlighty.HostCfg{
11     Root: "/www/example.com",
12     TLS: &godlighty.TLSCfg{
13         Cert: "/path/to/example.com.pem",
14         Key: "/path/to/example.com.key.pem",
15         CACert: "/path/to/ca.pem",
16     },
17     DirList: true,
18     WebDAV: true,
19     MIMEs: map[string]string{
20         ".special": "text/x-special-type",
21     },
22 }
23 @end verbatim
24
25 If your keys and certificates are in single file and you use common CA
26 certificate, then it is trivial to DRY:
27
28 @verbatim
29 var (
30     Etc = "/whatever"
31     CACert = path.Join(Etc, "ca.pem")
32 )
33
34 func newTLSCfg(host string) *godlighty.TLSCfg {
35     return &godlighty.TLSCfg{
36         Cert:   path.Join(Etc, host+".pem"),
37         Key:    path.Join(Etc, host+".pem"),
38         CACert: CACert,
39     }
40 }
41 @end verbatim
42
43 But there are hooks that can do anything more. For example if you want
44 to run CGI script or make a redirection (FastCGI handler example is in
45 @file{rc/fcgi.example.cfg}):
46
47 @verbatim
48 HostCfg{
49     ...,
50     Hooks: []godlighty.Hook{
51         func(w http.ResponseWriter, r *http.Request) bool {
52             if r.URL.Path == "/" {
53                 http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
54                 return true
55             }
56             return false
57         },
58         func(w http.ResponseWriter, r *http.Request) bool {
59             cgi.Handler{
60                 Path: "/usr/local/libexec/git-core/git-http-backend",
61                 Dir:  "/var/empty",
62                 Env: []string{
63                     "GIT_PROJECT_ROOT=" + root,
64                     "GIT_HTTP_EXPORT_ALL=",
65                 },
66             }.ServeHTTP(w, r)
67             return true
68         },
69     },
70 @end verbatim
71
72 You can separate your configuration files and add them through
73 @code{init()} call:
74
75 @verbatim
76 $ ls rc/stargrave.org.cfg
77 blog.stargrave.org.go
78 ca.cypherpunks.ru.go
79 cgi.go
80 cryptoanarchy.ru.go
81 git.go
82 go.go
83 if.mirror.cypherpunks.ru.go
84 lists.cypherpunks.ru.go
85 static.go
86 tls.go
87 [...]
88
89 $ cat rc/stargrave.org.cfg/static.go
90 package rc
91
92 import "path"
93
94 func addStaticCfg(host, root string) {
95     if !path.IsAbs(root) {
96         root = path.Join(WWW, root)
97     }
98     godlighty.Hosts[host] = &godlighty.HostCfg{
99         Root: root,
100         TLS:  newTLSCfg(host),
101     }
102 }
103
104 func addStaticListedDir(host, root string) {
105     addStaticCfg(host, root)
106     godlighty.Hosts[host].DirList = true
107     godlighty.Hosts[host].WebDAV = true
108 }
109
110 func init() {
111     [...]
112     addStaticCfg("paster.stargrave.org", "/storage/paster/pastes")
113     addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org")
114     addStaticCfg("www.nncpgo.org", "nncpgo.org")
115     addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds")
116     [...]
117 }
118 @end verbatim
119
120 There are some preexisting helpers to deal with:
121
122 @table @file
123
124 @item rc/cgi.go
125 CGI scripts.
126
127 @item rc/redirect.go
128 Loggable redirects.
129
130 @item rc/mime.go, rc/mime/*
131 Predefined @code{Content-Type} entries. Each file in @file{rc/mime/*}
132 has tab-separated format: file's extension, media type and optional
133 @code{c} mark, meaning that these type can be transparently compressed
134 on-the-fly.
135
136 @end table