package main import ( "context" "log" "os" "os/signal" "syscall" "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/contrib/cgi" "tildegit.org/tjp/sliderule/gemini" "tildegit.org/tjp/sliderule/logging" ) func main() { // GET TLS files from the environment certfile, keyfile := envConfig() // build a TLS configuration suitable for gemini tlsconf, err := gemini.FileTLS(certfile, keyfile) if err != nil { log.Fatal(err) } // make use of a CGI request handler cgiHandler := cgi.GeminiCGIDirectory("./cgi-bin", "/cgi-bin", "") baseLog := logging.Base() // add stdout logging to the request handler handler := logging.LogRequests(level.Info(baseLog))(cgiHandler) // set up signals to trigger graceful shutdown ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGHUP) defer stop() // run the server server, err := gemini.NewServer(ctx, "localhost", "tcp4", ":1965", handler, baseLog, tlsconf) if err != nil { log.Fatal(err) } defer server.Close() if err := server.Serve(); err != nil { log.Fatal(err) } } func envConfig() (string, string) { certfile, ok := os.LookupEnv("SERVER_CERTIFICATE") if !ok { log.Fatal("missing SERVER_CERTIFICATE environment variable") } keyfile, ok := os.LookupEnv("SERVER_PRIVATEKEY") if !ok { log.Fatal("missing SERVER_PRIVATEKEY environment variable") } return certfile, keyfile }