diff options
| author | Adnan Maolood <[email protected]> | 2021-02-20 18:52:33 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-02-20 18:52:33 -0500 |
| commit | 7668345daac1829de1b20bf5cefe5d6b6f3a096a (patch) | |
| tree | a20f6c3ef470f9d316a13bb9bae168201a19dc7e /server.go | |
| parent | Update examples (diff) | |
| download | go-gemini-7668345daac1829de1b20bf5cefe5d6b6f3a096a.tar.xz go-gemini-7668345daac1829de1b20bf5cefe5d6b6f3a096a.zip | |
server: Add Context field
Diffstat (limited to 'server.go')
| -rw-r--r-- | server.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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...) |