Move to the layout REPO_POLICIES.md gives (closes #30)
check / check (push) Successful in 2m32s
check / check (push) Successful in 2m32s
The Go module moves from backend/ to the root (go.mod, go.sum, .golangci.yml, cmd/, internal/), the page's source to web/, and nginx's two files to configs/. backend/ is gone: its LICENSE and .dockerignore are deleted, and its .gitignore entries, README and scripts are folded into the root ones. script/build builds the server binary after the frontend; script/run and script/clean move up from backend/script/; make test, lint, fmt and fmt-check do what the backend's did. Vite's root is web/ and it still builds into dist/. script/bootstrap no longer installs gcc, which only the host Go tests needed. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
const (
|
||||
readTimeout = 10 * time.Second
|
||||
readHeaderTimeout = 5 * time.Second
|
||||
idleTimeout = 60 * time.Second
|
||||
maxHeaderBytes = 1 << 20 // 1 MiB
|
||||
|
||||
// requestTimeout (routes.go) is the single per-request
|
||||
// processing budget, enforced by chi's middleware.Timeout.
|
||||
// writeTimeout must exceed that budget so a handler can write
|
||||
// its 503 when the chi timeout fires; if it were shorter the
|
||||
// server would abort the write first and the chi budget would
|
||||
// be unreachable dead configuration.
|
||||
writeTimeout = requestTimeout + 5*time.Second
|
||||
)
|
||||
|
||||
// newHTTPServer constructs the http.Server. It performs no I/O
|
||||
// and does not start listening.
|
||||
func (s *Server) newHTTPServer() *http.Server {
|
||||
listenAddr := net.JoinHostPort(
|
||||
s.params.Config.BindAddress,
|
||||
strconv.Itoa(s.params.Config.Port),
|
||||
)
|
||||
|
||||
return &http.Server{
|
||||
Addr: listenAddr,
|
||||
Handler: s,
|
||||
MaxHeaderBytes: maxHeaderBytes,
|
||||
ReadTimeout: readTimeout,
|
||||
ReadHeaderTimeout: readHeaderTimeout,
|
||||
WriteTimeout: writeTimeout,
|
||||
IdleTimeout: idleTimeout,
|
||||
}
|
||||
}
|
||||
|
||||
// listenAndServe runs the listener until the server is shut
|
||||
// down. A genuine listen failure (not the expected
|
||||
// ErrServerClosed from a clean shutdown) requests process
|
||||
// shutdown through fx with a non-zero exit code, so the failure
|
||||
// is visible to any supervisor.
|
||||
func (s *Server) listenAndServe() {
|
||||
s.log.Info("http begin listen",
|
||||
"listenaddr", s.httpServer.Addr,
|
||||
"version", s.params.Globals.Version,
|
||||
"arch", runtime.GOARCH,
|
||||
)
|
||||
|
||||
err := s.httpServer.ListenAndServe()
|
||||
if err == nil || errors.Is(err, http.ErrServerClosed) {
|
||||
return
|
||||
}
|
||||
|
||||
s.log.Error("listen error", "error", err)
|
||||
|
||||
shutdownErr := s.shutdowner.Shutdown(fx.ExitCode(1))
|
||||
if shutdownErr != nil {
|
||||
s.log.Error("request shutdown failed", "error", shutdownErr)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user