Skip to content

Commit

Permalink
refactor(mgmt): add configurable port (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
siohaza authored May 19, 2024
1 parent b630633 commit b88e1ab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
Expand Down
6 changes: 3 additions & 3 deletions server/http/mgmt_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/google/uuid"

"github.com/mk6i/retro-aim-server/config"
"github.com/mk6i/retro-aim-server/state"
)

Expand Down Expand Up @@ -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()}
Expand All @@ -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())
Expand Down

0 comments on commit b88e1ab

Please sign in to comment.