From a4a01ee734a5b94ece86c2b114657cd5ada1e237 Mon Sep 17 00:00:00 2001
From: Philipp Trulson
Date: Tue, 3 Dec 2024 15:24:23 +0100
Subject: [PATCH] Make admin API configurable
---
pkg/webutil/admin.go | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/pkg/webutil/admin.go b/pkg/webutil/admin.go
index 726604b..320e6a9 100644
--- a/pkg/webutil/admin.go
+++ b/pkg/webutil/admin.go
@@ -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()
@@ -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")
})
@@ -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())
}