diff options
author | Alan Pearce | 2024-06-18 15:58:53 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-18 15:58:53 +0200 |
commit | a238c7e0889cbe7dfaa1a700dea30686a4e2139a (patch) | |
tree | 812878165bb8bdfe1f7fa28921b9ceae2e8fd45f /internal/server/server.go | |
parent | f69b6432cd1f921909b254c1adc93080e844f2f5 (diff) | |
download | website-a238c7e0889cbe7dfaa1a700dea30686a4e2139a.tar.lz website-a238c7e0889cbe7dfaa1a700dea30686a4e2139a.tar.zst website-a238c7e0889cbe7dfaa1a700dea30686a4e2139a.zip |
extract socket passing protocol handler to package
Diffstat (limited to 'internal/server/server.go')
-rw-r--r-- | internal/server/server.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/internal/server/server.go b/internal/server/server.go index d2939ca..1b0407d 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -6,12 +6,12 @@ import ( "net" "net/http" "net/url" - "os" "slices" "time" "website/internal/builder" cfg "website/internal/config" + "website/internal/listenfd" "website/internal/log" "website/internal/website" @@ -161,14 +161,18 @@ func New(runtimeConfig *Config) (*Server, error) { } func (s *Server) Start() error { - f := os.NewFile(uintptr(3), "") - l, err := net.FileListener(f) + l, err := listenfd.GetListener(0) if err != nil { + log.Warn("could not create listener from listenfd", "error", err) + } + + if l == nil { l, err = net.Listen("tcp", s.Addr) if err != nil { return errors.Wrap(err, "could not create listener") } } + if err := http.Serve(l, s.Handler); err != http.ErrServerClosed { return errors.Wrap(err, "error creating/closing server") } |