From b88e1ab78f9251d3d231b7935676cb18ec95f4aa Mon Sep 17 00:00:00 2001 From: siohaza Date: Sun, 19 May 2024 10:21:22 +0000 Subject: [PATCH] refactor(mgmt): add configurable port (#26) --- cmd/server/main.go | 2 +- config/config.go | 1 + server/http/mgmt_api.go | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 5994466b..892913d4 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -40,7 +40,7 @@ func main() { wg.Add(6) go func() { - http.StartManagementAPI(feedbagStore, sessionManager, logger) + http.StartManagementAPI(cfg, feedbagStore, sessionManager, logger) wg.Done() }() go func(logger *slog.Logger) { diff --git a/config/config.go b/config/config.go index 4a58e9b6..1faf4901 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config //go:generate go run github.com/mk6i/retro-aim-server/cmd/config_generator windows settings.bat //go:generate go run github.com/mk6i/retro-aim-server/cmd/config_generator unix settings.env type Config struct { + ApiPort string `envconfig:"API_PORT" required:"true" val:"8080" description:"The port that the management API service binds to."` AlertPort string `envconfig:"ALERT_PORT" required:"true" val:"5194" description:"The port that the Alert service binds to."` AuthPort string `envconfig:"AUTH_PORT" required:"true" val:"5190" description:"The port that the auth service binds to."` BOSPort string `envconfig:"BOS_PORT" required:"true" val:"5191" description:"The port that the BOS service binds to."` diff --git a/server/http/mgmt_api.go b/server/http/mgmt_api.go index 213c6391..7c58c40f 100644 --- a/server/http/mgmt_api.go +++ b/server/http/mgmt_api.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" + "github.com/mk6i/retro-aim-server/config" "github.com/mk6i/retro-aim-server/state" ) @@ -38,7 +39,7 @@ type SessionRetriever interface { AllSessions() []*state.Session } -func StartManagementAPI(userManager UserManager, sessionRetriever SessionRetriever, logger *slog.Logger) { +func StartManagementAPI(cfg config.Config, userManager UserManager, sessionRetriever SessionRetriever, logger *slog.Logger) { mux := http.NewServeMux() newUser := func() state.User { return state.User{AuthKey: uuid.New().String()} @@ -53,8 +54,7 @@ func StartManagementAPI(userManager UserManager, sessionRetriever SessionRetriev sessionHandler(w, r, sessionRetriever) }) - //todo make port configurable - addr := net.JoinHostPort("", "8080") + addr := net.JoinHostPort("", cfg.ApiPort) logger.Info("starting management API server", "addr", addr) if err := http.ListenAndServe(addr, mux); err != nil { logger.Error("unable to bind management API address address", "err", err.Error())