diff options
Diffstat (limited to 'examples/cgi')
-rw-r--r-- | examples/cgi/main.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/cgi/main.go b/examples/cgi/main.go index d1df220..3dfec29 100644 --- a/examples/cgi/main.go +++ b/examples/cgi/main.go @@ -4,6 +4,8 @@ import ( "context" "log" "os" + "os/signal" + "syscall" "tildegit.org/tjp/gus/contrib/cgi" guslog "tildegit.org/tjp/gus/contrib/log" @@ -26,12 +28,20 @@ func main() { // add stdout logging to the request handler handler := guslog.Requests(os.Stdout, nil)(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(context.Background(), tlsconf, "tcp4", ":1965", handler) + server, err := gemini.NewServer(ctx, tlsconf, "tcp4", ":1965", handler) if err != nil { log.Fatal(err) } - server.Serve() + defer server.Close() + + if err := server.Serve(); err != nil { + log.Fatal(err) + } } func envConfig() (string, string) { |