diff options
| author | Paul Buetow <openbsd@mx.buetow.org> | 2021-12-28 18:35:44 +0100 |
|---|---|---|
| committer | Paul Buetow <openbsd@mx.buetow.org> | 2021-12-28 18:35:44 +0100 |
| commit | a442b330ceccce973d66af974e973dfcf9314037 (patch) | |
| tree | 9cdd9d3fbe407914230a3b5850fdb4641002116a /openbsd | |
| parent | 2b86e51eca4dc1ef8fff6ba1fea9b1b235a740c7 (diff) | |
add custom gemini server main function
Diffstat (limited to 'openbsd')
| -rw-r--r-- | openbsd/blowfish.buetow.org/opt/src/gemini/README.md | 10 | ||||
| -rw-r--r-- | openbsd/blowfish.buetow.org/opt/src/gemini/myserver/main.go | 65 |
2 files changed, 75 insertions, 0 deletions
diff --git a/openbsd/blowfish.buetow.org/opt/src/gemini/README.md b/openbsd/blowfish.buetow.org/opt/src/gemini/README.md new file mode 100644 index 0000000..b056838 --- /dev/null +++ b/openbsd/blowfish.buetow.org/opt/src/gemini/README.md @@ -0,0 +1,10 @@ +Custom gemini server configuration +================================= + +``` +git clone https://github.com/a-h/gemini +cp -Rpv ./myserver ./gemini/myserver +cd ./gemini/myserver +go build main.go +doas cp -p ./main /usr/local/bin/geminid +``` diff --git a/openbsd/blowfish.buetow.org/opt/src/gemini/myserver/main.go b/openbsd/blowfish.buetow.org/opt/src/gemini/myserver/main.go new file mode 100644 index 0000000..09bcb3f --- /dev/null +++ b/openbsd/blowfish.buetow.org/opt/src/gemini/myserver/main.go @@ -0,0 +1,65 @@ +package main + +import ( + "context" + "crypto/tls" + "fmt" + "os" + "time" + + "github.com/a-h/gemini" +) + +type configuration struct { + // Domain name, e.g. localhost. + domain string + // Certfile is the path to a server cerfificate file. + certFile string + // Keyfile is the path to a server key file. + keyFile string + // Path to Gemini content to serve. + path string +} + +func main() { + config := []configuration{ + { + domain: "buetow.org", + certFile: "/etc/ssl/buetow.org.fullchain.pem", + keyFile: "/etc/ssl/private/buetow.org.key", + path: "/var/gemini/gemtexter/buetow.org", + }, + { + domain: "snonux.de", + certFile: "/etc/ssl/snonux.de.fullchain.pem", + keyFile: "/etc/ssl/private/snonux.de.key", + path: "/var/gemini/gemtexter/snonux.de", + }, + } + + // Load the config. + domainToHandler := map[string]*gemini.DomainHandler{} + + for i := 0; i < len(config); i++ { + c := config[i] + h := gemini.FileSystemHandler(gemini.Dir(c.path)) + cert, err := tls.LoadX509KeyPair(c.certFile, c.keyFile) + if err != nil { + fmt.Printf("error: failed to load certificates for domain %q: %v\n", c.domain, err) + os.Exit(1) + } + dh := gemini.NewDomainHandler(c.domain, cert, h) + domainToHandler[c.domain] = dh + } + + // Start the server. + ctx := context.Background() + server := gemini.NewServer(ctx, ":1965", domainToHandler) + server.ReadTimeout = time.Second * 5 + server.WriteTimeout = time.Second * 10 + err := server.ListenAndServe() + if err != nil { + fmt.Printf("error: %v\n", err) + os.Exit(1) + } +} |
