Commit 857af59

mo khan <mo@mokhan.ca>
2025-03-13 16:04:25
refactor: extract WithRoutes config option
1 parent d442b77
Changed files (2)
cmd
pkg
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(),
 	)))
 }
pkg/cfg/tls.go
@@ -6,10 +6,10 @@ import (
 	"github.com/xlgmokha/x/pkg/x"
 )
 
-func WithSelfSigned(cert, key string) cfg.Option {
+func WithSelfSigned(cert, key string) Option {
 	certificate := x.Must(tls.LoadX509KeyPair(cert, key))
 
-	return func(config *cfg.Config) {
+	return func(config *Config) {
 		config.TLS = &tls.Config{
 			MinVersion:   tls.VersionTLS13,
 			Certificates: []tls.Certificate{certificate},