From: Sergey Matveev Date: Mon, 4 Oct 2021 09:21:46 +0000 (+0300) Subject: Move domain-specific things to separate directory X-Git-Url: http://www.git.stargrave.org/?p=godlighty.git;a=commitdiff_plain;h=49ca573fec30b4c5565fa73635b768a5d7abf94a Move domain-specific things to separate directory --- diff --git a/cmd/godlighty/main.go b/cmd/godlighty/main.go index 46c5d87..22f0c22 100644 --- a/cmd/godlighty/main.go +++ b/cmd/godlighty/main.go @@ -34,7 +34,7 @@ import ( "golang.org/x/net/netutil" "go.stargrave.org/godlighty" - _ "go.stargrave.org/godlighty/rc" + _ "go.stargrave.org/godlighty/rc/cfg" ) const MaxConns = 128 diff --git a/doc/index.texi b/doc/index.texi index bbc53e7..3923ab9 100644 --- a/doc/index.texi +++ b/doc/index.texi @@ -64,7 +64,7 @@ Hosts["example.com"] = &godlighty.HostCfg{ }, DirList: true, WebDAV: true, - MIMEOverride: map[string]string{ + MIMEs: map[string]string{ ".special": "text/x-special-type", }, } diff --git a/godlighty.do b/godlighty.do index 046dc11..ba66eda 100644 --- a/godlighty.do +++ b/godlighty.do @@ -1,2 +1,2 @@ -redo-ifchange cmd/godlighty/*.go *.go go.* rc/*.go rc/mime/* +redo-ifchange cmd/godlighty/*.go *.go go.* rc/*.go rc/mime/* rc/cfg/*.go ${GO:-go} build -o $3 -ldflags=-s ./cmd/godlighty diff --git a/rc/cfg b/rc/cfg new file mode 120000 index 0000000..2681394 --- /dev/null +++ b/rc/cfg @@ -0,0 +1 @@ +example.cfg \ No newline at end of file diff --git a/rc/cgi.go b/rc/cgi.go index 18011d9..42363e3 100644 --- a/rc/cgi.go +++ b/rc/cgi.go @@ -25,7 +25,7 @@ import ( "go.stargrave.org/godlighty" ) -func runCGIAndLog(host string, w http.ResponseWriter, r *http.Request, h *cgi.Handler) { +func RunCGIAndLog(host string, w http.ResponseWriter, r *http.Request, h *cgi.Handler) { wc := &godlighty.CountResponseWriter{ResponseWriter: w} h.ServeHTTP(wc, r) fmt.Printf("%s %s \"%s %s %s\" %d %d \"%s\"\n", diff --git a/rc/cryptoanarchy.ru.go b/rc/cryptoanarchy.ru.go deleted file mode 100644 index 81c85d5..0000000 --- a/rc/cryptoanarchy.ru.go +++ /dev/null @@ -1,23 +0,0 @@ -package rc - -import ( - "net/http" - - "go.stargrave.org/godlighty" -) - -func init() { - host := "www.cryptoanarchy.ru" - godlighty.Hosts[host] = &godlighty.HostCfg{ - Hooks: []godlighty.Hook{ - func(w http.ResponseWriter, r *http.Request) bool { - redirect( - host, w, r, - "//www.cypherpunks.ru/Manifesto-cryptoanarchist.html", - http.StatusMovedPermanently, - ) - return true - }, - }, - } -} diff --git a/rc/blog.stargrave.org.go b/rc/example.cfg/blog.stargrave.org.go similarity index 52% rename from rc/blog.stargrave.org.go rename to rc/example.cfg/blog.stargrave.org.go index af005d5..22ce4a4 100644 --- a/rc/blog.stargrave.org.go +++ b/rc/example.cfg/blog.stargrave.org.go @@ -1,21 +1,4 @@ -/* -godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -Copyright (C) 2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package rc +package cfg import ( "net/http" @@ -24,6 +7,7 @@ import ( "strings" "go.stargrave.org/godlighty" + "go.stargrave.org/godlighty/rc" ) func init() { @@ -45,7 +29,7 @@ func init() { return false } r.URL.Path = strings.TrimPrefix(r.URL.Path, "/"+t) - runCGIAndLog(host, w, r, &cgi.Handler{ + rc.RunCGIAndLog(host, w, r, &cgi.Handler{ Path: "/home/sgblog/sgblog", Dir: "/var/empty", Env: []string{"SGBLOG_CFG=/home/sgblog/" + t + ".hjson"}, diff --git a/rc/git.go b/rc/example.cfg/git.go similarity index 84% rename from rc/git.go rename to rc/example.cfg/git.go index 65498b1..1e955ed 100644 --- a/rc/git.go +++ b/rc/example.cfg/git.go @@ -1,10 +1,11 @@ -package rc +package cfg import ( "net/http" "net/http/cgi" "go.stargrave.org/godlighty" + "go.stargrave.org/godlighty/rc" ) func addGitRepoCfg(host, root, gitwebCfg string) { @@ -13,13 +14,13 @@ func addGitRepoCfg(host, root, gitwebCfg string) { Hooks: []godlighty.Hook{ func(w http.ResponseWriter, r *http.Request) bool { if r.URL.Path == "/" { - redirect(host, w, r, "//"+host+"/", http.StatusMovedPermanently) + rc.Redirect(host, w, r, "//"+host+"/", http.StatusMovedPermanently) return true } return false }, func(w http.ResponseWriter, r *http.Request) bool { - runCGIAndLog(host, w, r, &cgi.Handler{ + rc.RunCGIAndLog(host, w, r, &cgi.Handler{ Path: "/usr/local/libexec/git-core/git-http-backend", Dir: "/var/empty", Env: []string{ @@ -38,7 +39,7 @@ func addGitRepoCfg(host, root, gitwebCfg string) { Hooks: []godlighty.Hook{ func(w http.ResponseWriter, r *http.Request) bool { if r.URL.Path == "/" { - runCGIAndLog(host, w, r, &cgi.Handler{ + rc.RunCGIAndLog(host, w, r, &cgi.Handler{ Path: "/usr/local/share/gitweb/gitweb.cgi", Env: []string{"GITWEB_CONFIG=" + gitwebCfg}, }) diff --git a/rc/example.cfg/go.go b/rc/example.cfg/go.go new file mode 100644 index 0000000..6d905d3 --- /dev/null +++ b/rc/example.cfg/go.go @@ -0,0 +1,20 @@ +package cfg + +import ( + "path" + + "go.stargrave.org/godlighty" +) + +func addGoRepoCfg(host string) { + godlighty.Hosts[host] = &godlighty.HostCfg{ + Root: path.Join(WWW, host), + TLS: newTLSCfg(host), + MIMEs: map[string]string{"": "text/html"}, + } +} + +func init() { + addGoRepoCfg("go.cypherpunks.ru") + addGoRepoCfg("go.stargrave.org") +} diff --git a/rc/if.mirror.cypherpunks.ru.go b/rc/example.cfg/if.mirror.cypherpunks.ru.go similarity index 96% rename from rc/if.mirror.cypherpunks.ru.go rename to rc/example.cfg/if.mirror.cypherpunks.ru.go index dad2b39..1e1a1da 100644 --- a/rc/if.mirror.cypherpunks.ru.go +++ b/rc/example.cfg/if.mirror.cypherpunks.ru.go @@ -1,4 +1,4 @@ -package rc +package cfg import "go.stargrave.org/godlighty" diff --git a/rc/example.cfg/lists.cypherpunks.ru.go b/rc/example.cfg/lists.cypherpunks.ru.go new file mode 100644 index 0000000..20b2e63 --- /dev/null +++ b/rc/example.cfg/lists.cypherpunks.ru.go @@ -0,0 +1,29 @@ +package cfg + +import ( + "net/http" + "path" + "strings" + + "go.stargrave.org/godlighty" +) + +func init() { + host := "lists.cypherpunks.ru" + godlighty.Hosts[host] = &godlighty.HostCfg{ + Root: path.Join(WWW, host), + TLS: newTLSCfg(host), + Hooks: []godlighty.Hook{ + func(w http.ResponseWriter, r *http.Request) bool { + if strings.HasPrefix(r.URL.Path, "/archive/") { + r.URL.Path = strings.TrimPrefix(r.URL.Path, "/archive") + godlighty.MainHandler.Handle(w, r, host, &godlighty.HostCfg{ + Root: "/home/mlmmj/archive", + }) + return true + } + return false + }, + }, + } +} diff --git a/rc/proxied-host.go b/rc/example.cfg/proxied-host.go similarity index 98% rename from rc/proxied-host.go rename to rc/example.cfg/proxied-host.go index 8877007..1ad0db6 100644 --- a/rc/proxied-host.go +++ b/rc/example.cfg/proxied-host.go @@ -1,4 +1,4 @@ -package rc +package cfg import ( "fmt" diff --git a/rc/root.go b/rc/example.cfg/root.go similarity index 93% rename from rc/root.go rename to rc/example.cfg/root.go index 6151aa2..e20228e 100644 --- a/rc/root.go +++ b/rc/example.cfg/root.go @@ -1,4 +1,4 @@ -package rc +package cfg import "path" diff --git a/rc/static.go b/rc/example.cfg/static.go similarity index 52% rename from rc/static.go rename to rc/example.cfg/static.go index 89142a8..f1559c8 100644 --- a/rc/static.go +++ b/rc/example.cfg/static.go @@ -1,21 +1,4 @@ -/* -godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -Copyright (C) 2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package rc +package cfg import ( "path" @@ -44,6 +27,7 @@ func addStaticWebDAVedDir(host, root string) { godlighty.Hosts[host].WebDAV = true } + func init() { addStaticCfg("www.stargrave.org", "stargrave.org") diff --git a/rc/example.cfg/tls.go b/rc/example.cfg/tls.go new file mode 100644 index 0000000..1a4cd7b --- /dev/null +++ b/rc/example.cfg/tls.go @@ -0,0 +1,15 @@ +package cfg + +import ( + "path" + + "go.stargrave.org/godlighty" +) + +func newTLSCfg(host string) *godlighty.TLSCfg { + return &godlighty.TLSCfg{ + Cert: path.Join(Etc, host+".pem"), + Key: path.Join(Etc, host+".pem"), + CACert: CACert, + } +} diff --git a/rc/go.go b/rc/go.go deleted file mode 100644 index e4b0d8e..0000000 --- a/rc/go.go +++ /dev/null @@ -1,37 +0,0 @@ -/* -godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -Copyright (C) 2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package rc - -import ( - "path" - - "go.stargrave.org/godlighty" -) - -func addGoRepoCfg(host string) { - godlighty.Hosts[host] = &godlighty.HostCfg{ - Root: path.Join(WWW, host), - TLS: newTLSCfg(host), - MIMEs: map[string]string{"": "text/html"}, - } -} - -func init() { - addGoRepoCfg("go.cypherpunks.ru") - addGoRepoCfg("go.stargrave.org") -} diff --git a/rc/lists.cypherpunks.ru.go b/rc/lists.cypherpunks.ru.go deleted file mode 100644 index 31e8148..0000000 --- a/rc/lists.cypherpunks.ru.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -Copyright (C) 2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package rc - -import ( - "net/http" - "path" - "strings" - - "go.stargrave.org/godlighty" -) - -func init() { - host := "lists.cypherpunks.ru" - godlighty.Hosts[host] = &godlighty.HostCfg{ - Root: path.Join(WWW, host), - TLS: newTLSCfg(host), - Hooks: []godlighty.Hook{ - func(w http.ResponseWriter, r *http.Request) bool { - if strings.HasPrefix(r.URL.Path, "/archive/") { - r.URL.Path = strings.TrimPrefix(r.URL.Path, "/archive") - godlighty.MainHandler.Handle(w, r, host, &godlighty.HostCfg{ - Root: "/home/mlmmj/archive", - }) - return true - } - return false - }, - }, - } -} diff --git a/rc/redirect.go b/rc/redirect.go index 86a6210..ecbdbfb 100644 --- a/rc/redirect.go +++ b/rc/redirect.go @@ -22,7 +22,7 @@ import ( "net/http" ) -func redirect( +func Redirect( host string, w http.ResponseWriter, r *http.Request, to string, status int, diff --git a/rc/tls.go b/rc/tls.go deleted file mode 100644 index faf5473..0000000 --- a/rc/tls.go +++ /dev/null @@ -1,32 +0,0 @@ -/* -godlighty -- highly-customizable HTTP, HTTP/2, HTTPS server -Copyright (C) 2021 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package rc - -import ( - "path" - - "go.stargrave.org/godlighty" -) - -func newTLSCfg(host string) *godlighty.TLSCfg { - return &godlighty.TLSCfg{ - Cert: path.Join(Etc, host+".pem"), - Key: path.Join(Etc, host+".pem"), - CACert: CACert, - } -}