summaryrefslogtreecommitdiff
path: root/cmd/gtwy/main.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-13 09:12:17 -0600
committermo khan <mo@mokhan.ca>2025-03-13 09:12:17 -0600
commit6ad85c4bd167c9f114c1d2574f4887826689b76d (patch)
treeb45f77c71163b7a637ce3d4a5db87f46e67a7659 /cmd/gtwy/main.go
parent0c50b105de6c0fc0c5a941af0adf59a40124ecb1 (diff)
refactor: extract srv package
Diffstat (limited to 'cmd/gtwy/main.go')
-rw-r--r--cmd/gtwy/main.go21
1 files changed, 7 insertions, 14 deletions
diff --git a/cmd/gtwy/main.go b/cmd/gtwy/main.go
index 3d4a247..8d1baa6 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),
+ )))
}