From 857af592cfa293b1cd6821c26a91e5a9be5bc19c Mon Sep 17 00:00:00 2001 From: mo khan Date: Thu, 13 Mar 2025 10:04:25 -0600 Subject: refactor: extract WithRoutes config option --- cmd/gtwy/main.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'cmd') diff --git a/cmd/gtwy/main.go b/cmd/gtwy/main.go index 84c9f183..1e9d3a39 100644 --- a/cmd/gtwy/main.go +++ b/cmd/gtwy/main.go @@ -10,16 +10,22 @@ import ( "gitlab.com/mokhax/spike/pkg/srv" ) -func main() { - mux := http.NewServeMux() - mux.Handle("/", prxy.New(map[string]string{ - "idp.example.com": "localhost:8282", - "ui.example.com": "localhost:8283", - "api.example.com": "localhost:8284", - })) +func WithRoutes() cfg.Option { + return func(c *cfg.Config) { + mux := http.NewServeMux() + mux.Handle("/", prxy.New(map[string]string{ + "idp.example.com": "localhost:8282", + "ui.example.com": "localhost:8283", + "api.example.com": "localhost:8284", + })) + + cfg.WithMux(mux)(c) + } +} +func main() { log.Fatal(srv.Run(cfg.New( env.Fetch("BIND_ADDR", ":8080"), - cfg.WithMux(mux), + WithRoutes(), ))) } -- cgit v1.2.3