all repos — website @ a1ddbf3fa6d1814ebca238d0c4ed54617253689f

My website

server: listen on socket provided by system(f)d, if available

Alan Pearce
commit

a1ddbf3fa6d1814ebca238d0c4ed54617253689f

parent

66b66e6118dd43ccbd1e85e33d44a02de7a2b812

1 file changed, 10 insertions(+), 1 deletion(-)

changed files
M internal/server/server.gointernal/server/server.go
@@ -6,6 +6,7 @@ "fmt"
"net" "net/http" "net/url" + "os" "slices" "time"
@@ -145,7 +146,15 @@ }, nil
} func (s *Server) Start() error { - if err := s.ListenAndServe(); err != http.ErrServerClosed { + f := os.NewFile(uintptr(3), "") + l, err := net.FileListener(f) + if err != 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") }