Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(mgmt): add configurable port #26

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading