]> Sergey Matveev's repositories - godlighty.git/blob - doc/index.texi
Example daemontools run scripts
[godlighty.git] / doc / index.texi
1 \input texinfo
2 @documentencoding UTF-8
3 @settitle godlighty
4
5 @copying
6 Copyright @copyright{} 2021 @email{stargrave@@stargrave.org, Sergey Matveev}
7 @end copying
8
9 @node Top
10 @top godlighty
11
12 @command{godlighty} is highly-customizable HTTP, HTTP/2, HTTPS server
13 written on pure Go.
14
15 Why yet another web-server? Because all others suck even for my simple
16 ordinary needs: they use hateful OpenSSL, lacks documentation, has
17 complex configuration format, lack some features, hard to extend with.
18
19 @itemize
20
21 @item Rather minimalistic pure-Go web-server with few number of
22 dependencies, producing single statically linked executable. Maximal
23 reuse of native libraries capabilities.
24
25 @item Modern, reliable, secure and fast TLS 1.3 implementation with
26 ChaCha20-Poly1305, session resumption and GOST cryptography (if built
27 with @url{http://www.gostls13.cypherpunks.ru/, gostls13}). SNI supported.
28
29 @item HTTP/1.1, @url{https://en.wikipedia.org/wiki/HTTP%2F2, HTTP/2}
30 (only when negotiated during ALPN) and keepalives support. Graceful
31 shutdowns.
32
33 @item @code{gzip} and @url{https://facebook.github.io/zstd/, Zstandard}
34 compression on-the-fly.
35
36 @item @code{Range}, @code{ETag} (based on file/directory's
37 @code{ctime}), @code{Last-Modified} and corresponding precondition
38 handlers are fully used.
39
40 @item Auto-generated directory listings and
41 read-only @url{https://en.wikipedia.org/wiki/WebDAV, WebDAV} support.
42
43 @item Per-domain HTTP basic authorization and TLS client authentication.
44
45 @item If corresponding @file{.meta4} files are found, then @code{Link}
46 header is generated automatically to that
47 @url{http://www.metalinker.org/, Metalink}.
48
49 @item Very friendly to @url{http://cr.yp.to/daemontools.html, daemontools}.
50 Can drop (UID, GID, groups) privileges.
51
52 @end itemize
53
54 Basically all configuration is done directly inside source code. You
55 have to recompile it every time configuration changes. Is it a problem?
56 I doubt, because Go is very fast. But it produces huge statically linked
57 executables, you say! Use @command{bsdiff}/@command{bspatch}!
58
59 Send @code{SIGINFO} signal to get current daemon's configuration.
60
61 Initially @command{godlighty} has basic static files handlers (with
62 compression, HTTP preconditions are enabled of course). In the example
63 below there are nearly all default functions.
64
65 @verbatim
66 Hosts["example.com"] = &godlighty.HostCfg{
67     Root: "/www/example.com",
68     TLS: &godlighty.TLSCfg{
69         Cert: "/path/to/example.com.pem",
70         Key: "/path/to/example.com.key.pem",
71         CACert: "/path/to/ca.pem",
72     },
73     DirList: true,
74     WebDAV: true,
75     MIMEs: map[string]string{
76         ".special": "text/x-special-type",
77     },
78 }
79 @end verbatim
80
81 If your keys and certificates are in single file and you use common CA
82 certificate, then it is trivial to DRY:
83
84 @verbatim
85 var (
86     Etc = "/whatever"
87     CACert = path.Join(Etc, "ca.pem")
88 )
89
90 func newTLSCfg(host string) *godlighty.TLSCfg {
91     return &godlighty.TLSCfg{
92         Cert:   path.Join(Etc, host+".pem"),
93         Key:    path.Join(Etc, host+".pem"),
94         CACert: CACert,
95     }
96 }
97 @end verbatim
98
99 But there are hooks that can do anything more. For example if you want
100 to run CGI script or make a redirection:
101
102 @verbatim
103 HostCfg{
104     ...,
105     Hooks: []godlighty.Hook{
106         func(w http.ResponseWriter, r *http.Request) bool {
107             if r.URL.Path == "/" {
108                 http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
109                 return true
110             }
111             return false
112         },
113         func(w http.ResponseWriter, r *http.Request) bool {
114             cgi.Handler{
115                 Path: "/usr/local/libexec/git-core/git-http-backend",
116                 Dir:  "/var/empty",
117                 Env: []string{
118                     "GIT_PROJECT_ROOT=" + root,
119                     "GIT_HTTP_EXPORT_ALL=",
120                 },
121             }.ServeHTTP(w, r)
122             return true
123         },
124     },
125 @end verbatim
126
127 You can separate your configuration files and add them through
128 @code{init()} call:
129
130 @verbatim
131 $ ls rc
132 blog.stargrave.org.go
133 ca.cypherpunks.ru.go
134 cgi.go
135 cryptoanarchy.ru.go
136 git.go
137 go.go
138 if.mirror.cypherpunks.ru.go
139 lists.cypherpunks.ru.go
140 mime.go
141 static.go
142 tls.go
143 [...]
144
145 $ cat rc/static
146 package rc
147
148 import "path"
149
150 func addStaticCfg(host, root string) {
151     if !path.IsAbs(root) {
152         root = path.Join(WWW, root)
153     }
154     godlighty.Hosts[host] = &godlighty.HostCfg{
155         Root: root,
156         TLS:  newTLSCfg(host),
157     }
158 }
159
160 func addStaticListedDir(host, root string) {
161     addStaticCfg(host, root)
162     godlighty.Hosts[host].DirList = true
163     godlighty.Hosts[host].WebDAV = true
164 }
165
166 func init() {
167     [...]
168     addStaticCfg("paster.stargrave.org", "/storage/paster/pastes")
169     addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org")
170     addStaticCfg("www.nncpgo.org", "nncpgo.org")
171     addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds")
172     [...]
173 }
174 @end verbatim
175
176 It is created exclusively to drive my own websites, but if you are
177 interested, then @code{git clone git://git.stargrave.org/godlighty.git} it.
178
179 @bye