From 6ad85c4bd167c9f114c1d2574f4887826689b76d Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 13 Mar 2025 09:12:17 -0600 Subject: refactor: extract srv package --- cmd/gtwy/main.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'cmd') diff --git a/cmd/gtwy/main.go b/cmd/gtwy/main.go index 3d4a2472..8d1baa6f 100644 --- a/cmd/gtwy/main.go +++ b/cmd/gtwy/main.go @@ -6,11 +6,11 @@ import ( "net/http" "net/http/httputil" "strings" - "time" "github.com/casbin/casbin/v2" "github.com/xlgmokha/x/pkg/env" "github.com/xlgmokha/x/pkg/x" + "gitlab.com/mokhax/spike/pkg/srv" ) func NewRouter(routes map[string]string) http.Handler { @@ -48,21 +48,14 @@ func NewRouter(routes map[string]string) http.Handler { func main() { mux := http.NewServeMux() - routes := map[string]string{ + mux.Handle("/", NewRouter(map[string]string{ "idp.example.com": "localhost:8282", "ui.example.com": "localhost:8283", "api.example.com": "localhost:8284", - } - mux.Handle("/", NewRouter(routes)) + })) - bindAddress := env.Fetch("BIND_ADDR", ":8080") - log.Fatal((&http.Server{ - Addr: bindAddress, - Handler: mux, - ReadHeaderTimeout: 10 * time.Second, - ReadTimeout: 30 * time.Second, - WriteTimeout: 2 * time.Minute, - IdleTimeout: 5 * time.Minute, - ErrorLog: log.Default(), - }).ListenAndServe()) + log.Fatal(srv.Run(srv.NewConfig( + env.Fetch("BIND_ADDR", ":8080"), + srv.WithMux(mux), + ))) } -- cgit v1.2.3