about summary refs log tree commit diff stats
path: root/internal/server
diff options
context:
space:
mode:
authorAlan Pearce2024-05-22 18:03:22 +0200
committerAlan Pearce2024-05-22 18:03:22 +0200
commitea098ab11740fe4783694ff0122738b30e0c342f (patch)
treebcd50fdb6fc7ce9730c758f709aa6bf29a763ea9 /internal/server
parentaef028263229d8acda28b8e657413f7e9c187833 (diff)
downloadwebsite-ea098ab11740fe4783694ff0122738b30e0c342f.tar.lz
website-ea098ab11740fe4783694ff0122738b30e0c342f.tar.zst
website-ea098ab11740fe4783694ff0122738b30e0c342f.zip
refactor: lint with golangci-lint
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/logging.go8
-rw-r--r--internal/server/server.go17
2 files changed, 14 insertions, 11 deletions
diff --git a/internal/server/logging.go b/internal/server/logging.go
index 65dcb87..afcce6d 100644
--- a/internal/server/logging.go
+++ b/internal/server/logging.go
@@ -5,12 +5,12 @@ import (
 	"website/internal/log"
 )
 
-type loggingResponseWriter struct {
+type LoggingResponseWriter struct {
 	http.ResponseWriter
 	statusCode int
 }
 
-func (lrw *loggingResponseWriter) WriteHeader(code int) {
+func (lrw *LoggingResponseWriter) WriteHeader(code int) {
 	lrw.statusCode = code
 	// avoids warning: superfluous response.WriteHeader call
 	if lrw.statusCode != http.StatusOK {
@@ -18,8 +18,8 @@ func (lrw *loggingResponseWriter) WriteHeader(code int) {
 	}
 }
 
-func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
-	return &loggingResponseWriter{w, http.StatusOK}
+func NewLoggingResponseWriter(w http.ResponseWriter) *LoggingResponseWriter {
+	return &LoggingResponseWriter{w, http.StatusOK}
 }
 
 type wrappedHandlerOptions struct {
diff --git a/internal/server/server.go b/internal/server/server.go
index 4fda3dc..8838dbd 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -21,9 +21,9 @@ import (
 var config *cfg.Config
 
 var (
-	CommitSHA    string = "local"
-	ShortSHA     string = "local"
-	serverHeader string = fmt.Sprintf("website (%s)", ShortSHA)
+	CommitSHA    = "local"
+	ShortSHA     = "local"
+	serverHeader = fmt.Sprintf("website (%s)", ShortSHA)
 )
 
 type Config struct {
@@ -83,7 +83,7 @@ func New(runtimeConfig *Config) (*Server, error) {
 	top := http.NewServeMux()
 	mux, err := website.NewMux(config, runtimeConfig.Root)
 	if err != nil {
-		return nil, err
+		return nil, errors.Wrap(err, "could not create website mux")
 	}
 	log.Debug("binding main handler to", "host", runtimeConfig.BaseURL.Hostname()+"/")
 	hostname := runtimeConfig.BaseURL.Hostname()
@@ -95,14 +95,16 @@ func New(runtimeConfig *Config) (*Server, error) {
 		http.Redirect(w, r, newURL.String(), 301)
 	})
 
-	top.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
+	top.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
 		w.WriteHeader(http.StatusOK)
 	})
 
 	listenAddress := net.JoinHostPort(runtimeConfig.ListenAddress, runtimeConfig.Port)
+
 	return &Server{
 		&http.Server{
-			Addr: listenAddress,
+			Addr:              listenAddress,
+			ReadHeaderTimeout: 1 * time.Minute,
 			Handler: sentryHandler.Handle(
 				serverHeaderHandler(
 					wrapHandlerWithLogging(top, wrappedHandlerOptions{
@@ -116,8 +118,9 @@ func New(runtimeConfig *Config) (*Server, error) {
 
 func (s *Server) Start() error {
 	if err := s.ListenAndServe(); err != http.ErrServerClosed {
-		return err
+		return errors.Wrap(err, "error creating/closing server")
 	}
+
 	return nil
 }