aboutsummaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-20 18:52:33 -0500
committerAdnan Maolood <[email protected]>2021-02-20 18:52:33 -0500
commit7668345daac1829de1b20bf5cefe5d6b6f3a096a (patch)
treea20f6c3ef470f9d316a13bb9bae168201a19dc7e /server.go
parentUpdate examples (diff)
downloadgo-gemini-7668345daac1829de1b20bf5cefe5d6b6f3a096a.tar.xz
go-gemini-7668345daac1829de1b20bf5cefe5d6b6f3a096a.zip
server: Add Context field
Diffstat (limited to 'server.go')
-rw-r--r--server.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/server.go b/server.go
index 2ba3fea..779c003 100644
--- a/server.go
+++ b/server.go
@@ -47,6 +47,10 @@ type Server struct {
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger
+ // Context is the base context to use.
+ // If nil, context.Background is used.
+ Context context.Context
+
listeners map[*net.Listener]struct{}
conns map[*net.Conn]struct{}
done int32
@@ -304,12 +308,18 @@ func (srv *Server) respond(conn net.Conn) {
return
}
- // TODO: Allow configuring the server context
- ctx := context.Background()
+ ctx := srv.context()
h.ServeGemini(ctx, w, req)
w.Flush()
}
+func (srv *Server) context() context.Context {
+ if srv.Context != nil {
+ return srv.Context
+ }
+ return context.Background()
+}
+
func (srv *Server) logf(format string, args ...interface{}) {
if srv.ErrorLog != nil {
srv.ErrorLog.Printf(format, args...)