Skip to content

Commit

Permalink
Make admin API listener configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann committed Dec 3, 2024
1 parent 9bb95d2 commit 68b6821
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions pkg/webutil/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import (
"github.com/rebuy-de/rebuy-go-sdk/v8/pkg/logutil"
)

// Deprecated: Use AdminAPIListenAndServeWithAddress instead
func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) {
AdminAPIListenAndServeWithAddress(ctx, "0.0.0.0", "8090")
}

func AdminAPIListenAndServeWithAddress(ctx context.Context, host, port string) {
ctx = logutil.Start(ctx, "admin-api")
mux := http.NewServeMux()

Expand All @@ -22,15 +27,6 @@ func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) {
return
}

for _, h := range healthy {
err := h()
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
fmt.Fprintln(w, err.Error())
return
}
}

w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "OK")
})
Expand All @@ -51,9 +47,9 @@ func AdminAPIListenAndServe(ctx context.Context, healthy ...func() error) {
bg := context.Background()

go func() {
logutil.Get(ctx).Debugf("admin api listening on port 8090")
logutil.Get(ctx).Debugf("admin api listening on port %s", port)

err := ListenAndServeWithContext(bg, "0.0.0.0:8090", mux)
err := ListenAndServeWithContext(bg, fmt.Sprintf("%s:%s", host, port), mux)
if err != nil {
logutil.Get(ctx).Error(err.Error())
}
Expand Down

0 comments on commit 68b6821

Please sign in to comment.