package web import ( "fmt" "fuj-management/go/internal/config" "fuj-management/go/internal/services/membership" "fuj-management/go/internal/web/api" "fuj-management/go/internal/web/middleware" "log/slog" "net/http" ) // BuildInfo carries the linker-injected build metadata. type BuildInfo struct { Version string Commit string BuildDate string } // Run registers routes and starts the HTTP server on addr. func Run(logger *slog.Logger, addr string, build BuildInfo, sources membership.Sources, cfg config.Config) error { h := &api.Handler{ BuildVersion: build.Version, BuildCommit: build.Commit, BuildDate: build.BuildDate, Sources: sources, Config: cfg, Logger: logger, } mux := http.NewServeMux() mux.HandleFunc("GET /{$}", helloHandler(build)) mux.HandleFunc("GET /api/version", h.ServeVersion) mux.HandleFunc("GET /api/adults", h.ServeAdults) mux.HandleFunc("GET /api/juniors", h.ServeJuniors) mux.HandleFunc("GET /api/payments", h.ServePayments) logger.Info("starting server", "addr", addr) return http.ListenAndServe(addr, middleware.RequestTimer(logger, mux)) } func helloHandler(build BuildInfo) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") fmt.Fprintf(w, "fuj-go ok\nversion: %s\ncommit: %s\nbuilt: %s\n", build.Version, build.Commit, build.BuildDate) } }