]> Sergey Matveev's repositories - godlighty.git/blob - doc/index.texi
Initial documentation
[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.
31
32 @item @code{gzip} and @url{https://facebook.github.io/zstd/, Zstandard}
33 compression on-the-fly.
34
35 @item @code{Range}, @code{ETag} (based on file/directory's
36 @code{ctime}), @code{Last-Modified} and corresponding precondition
37 handlers are fully used.
38
39 @item Auto-generated directory listings and
40 read-only @url{https://en.wikipedia.org/wiki/WebDAV, WebDAV} support.
41
42 @item If corresponding @file{.meta4} files are found, then @code{Link}
43 header is generated automatically to that
44 @url{http://www.metalinker.org/, Metalink}.
45
46 @item Very friendly to @url{http://cr.yp.to/daemontools.html, daemontools}.
47 Can drop (UID, GID, groups) privileges.
48
49 @end itemize
50
51 Basically all configuration is done directly inside source code.
52 Initially @command{godlighty} has basic static files handlers (with
53 compression, HTTP preconditions are enabled of course). In the example
54 below there are nearly all default functions.
55
56 @verbatim
57 Hosts["example.com"] = &godlighty.HostCfg{
58     Root: "/www/example.com",
59     TLS: &godlighty.TLSCfg{
60         Cert: "/path/to/example.com.pem",
61         Key: "/path/to/example.com.key.pem",
62         CACert: "/path/to/ca.pem",
63     },
64     DirList: true,
65     WebDAV: true,
66     MIMEOverride: map[string]string{
67         ".special": "text/x-special-type",
68     },
69 }
70 @end verbatim
71
72 If your keys and certificates are in single file and you use common CA
73 certificate, then it is trivial to DRY:
74
75 @verbatim
76 var (
77     Etc = "/whatever"
78     CACert = path.Join(Etc, "ca.pem")
79 )
80
81 func newTLSCfg(host string) *godlighty.TLSCfg {
82     return &godlighty.TLSCfg{
83         Cert:   path.Join(Etc, host+".pem"),
84         Key:    path.Join(Etc, host+".pem"),
85         CACert: CACert,
86     }
87 }
88 @end verbatim
89
90 But there are hooks that can do anything more. For example if you want
91 to run CGI script or make a redirection:
92
93 @verbatim
94 HostCfg{
95     ...,
96     Hooks: []godlighty.Hook{
97         func(w http.ResponseWriter, r *http.Request) bool {
98             if r.URL.Path == "/" {
99                 http.Redirect(w, r, "//here.we.go/", http.StatusMovedPermanently)
100                 return true
101             }
102             return false
103         },
104         func(w http.ResponseWriter, r *http.Request) bool {
105             cgi.Handler{
106                 Path: "/usr/local/libexec/git-core/git-http-backend",
107                 Dir:  "/var/empty",
108                 Env: []string{
109                     "GIT_PROJECT_ROOT=" + root,
110                     "GIT_HTTP_EXPORT_ALL=",
111                 },
112             }.ServeHTTP(w, r)
113             return true
114         },
115     },
116 @end verbatim
117
118 You can separate your configuration files and add them through
119 @code{init()} call:
120
121 @verbatim
122 $ ls rc
123 blog.stargrave.org.go
124 ca.cypherpunks.ru.go
125 cgi.go
126 cryptoanarchy.ru.go
127 git.go
128 go.go
129 if.mirror.cypherpunks.ru.go
130 lists.cypherpunks.ru.go
131 mime.go
132 static.go
133 tls.go
134 [...]
135
136 $ cat rc/static
137 package rc
138
139 import "path"
140
141 func addStaticCfg(host, root string) {
142     if !path.IsAbs(root) {
143         root = path.Join(WWW, root)
144     }
145     godlighty.Hosts[host] = &godlighty.HostCfg{
146         Root: root,
147         TLS:  newTLSCfg(host),
148     }
149 }
150
151 func addStaticListedDir(host, root string) {
152     addStaticCfg(host, root)
153     godlighty.Hosts[host].DirList = true
154     godlighty.Hosts[host].WebDAV = true
155 }
156
157 func init() {
158     [...]
159     addStaticCfg("paster.stargrave.org", "/storage/paster/pastes")
160     addStaticCfg("www.godlighty.stargrave.org", "godlighty.stargrave.org")
161     addStaticCfg("www.nncpgo.org", "nncpgo.org")
162     addStaticListedDir("www.mds.cypherpunks.ru", "/storage/audiobook/mds")
163     [...]
164 }
165 @end verbatim
166
167 It is created exclusively to drive my own websites, but if you are
168 interested, then @code{git clone git://git.stargrave.org/godlighty.git} it.
169
170 @bye