about summary refs log tree commit diff stats
path: root/internal/server/server.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-13 17:08:33 +0200
committerAlan Pearce2024-06-13 17:08:33 +0200
commita1ddbf3fa6d1814ebca238d0c4ed54617253689f (patch)
tree376944e40581b5d8155ab4acf9a0011364041417 /internal/server/server.go
parent66b66e6118dd43ccbd1e85e33d44a02de7a2b812 (diff)
downloadwebsite-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.tar.lz
website-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.tar.zst
website-a1ddbf3fa6d1814ebca238d0c4ed54617253689f.zip
server: listen on socket provided by system(f)d, if available
Diffstat (limited to 'internal/server/server.go')
-rw-r--r--internal/server/server.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index 4692965..71b9199 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -6,6 +6,7 @@ import (
 	"net"
 	"net/http"
 	"net/url"
+	"os"
 	"slices"
 	"time"
 
@@ -145,7 +146,15 @@ func New(runtimeConfig *Config) (*Server, error) {
 }
 
 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")
 	}