diff --git a/cmd/api/main.go b/cmd/api/main.go index c0a43ae..ef5a3e5 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -93,7 +93,7 @@ func main() { }() sseserver.StartEventServer() rlog.Infoc(ctx, "Initializing health server") - _ = healthserver.Start(healthserver.ServerString(viper.GetString(configconsts.HEALTH_ENDPOINT))) + _ = healthserver.Start(healthserver.ServerString(apiconfig.GetHealthEndpoint())) if apiconnections.RabbitMQConnection.Ping() { switchboard.PublishStarted(ctx) diff --git a/go.mod b/go.mod index 1bf4958..4dc19a1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/NorskHelsenett/ror-api go 1.23.1 require ( - github.com/NorskHelsenett/ror v1.1.0 + github.com/NorskHelsenett/ror v1.1.1 github.com/blang/semver/v4 v4.0.0 github.com/coreos/go-oidc/v3 v3.12.0 github.com/dotse/go-health v0.2.6 diff --git a/go.sum b/go.sum index 3fc8b98..c84b4ae 100644 --- a/go.sum +++ b/go.sum @@ -14,8 +14,8 @@ github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3 h1:H5xDQaE3Xow github.com/AzureAD/microsoft-authentication-library-for-go v1.3.3/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc= github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE= -github.com/NorskHelsenett/ror v1.1.0 h1:gM3iW/yktkRUX1/zZgO2OXJkvVLS4jaYDhg0s7vRKcs= -github.com/NorskHelsenett/ror v1.1.0/go.mod h1:sCh2/8XYn75b/+yrrWwOXmyxw1i5wo9i4CDOZ5/2TGM= +github.com/NorskHelsenett/ror v1.1.1 h1:d4Mb8rXs7uijUXxUVwdEB5MITuM4RKH/sj+ci7znRoA= +github.com/NorskHelsenett/ror v1.1.1/go.mod h1:sCh2/8XYn75b/+yrrWwOXmyxw1i5wo9i4CDOZ5/2TGM= github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI= github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= diff --git a/hacks/vscode/launch.json b/hacks/vscode/launch.json index 93a3455..dc54348 100644 --- a/hacks/vscode/launch.json +++ b/hacks/vscode/launch.json @@ -15,7 +15,10 @@ "LOG_LEVEL": "debug", "GIN_MODE": "debug", "ALLOW_ORIGINS": "https://ror.sky.test.nhn.no;http://localhost:11000;http://127.0.0.1:11000", + "HTTP_HOST": "localhost", "HTTP_PORT": "10000", + "HTTP_HEALTH_HOST": "localhost", + "HTTP_HEALTH_PORT": "9999", "VAULT_URL": "http://localhost:8200", "MONGODB_PORT": "27017", "OPENTELEMETRY_COLLECTOR_ENDPOINT": "localhost:4317", @@ -27,7 +30,6 @@ "CONTAINER_REG_IMAGE_PATH": "nhnsdi/", "CONTAINER_REG_HELM_PATH": "nhnhelm/", "LOCAL_KUBERNETES_ROR_BASE_URL": "http://host.docker.internal:10000", - "HEALTHCHECK_ENDPOINT": "localhost:9999" } }, { diff --git a/internal/apiconfig/viper.go b/internal/apiconfig/viper.go index 6c540a2..de221ec 100644 --- a/internal/apiconfig/viper.go +++ b/internal/apiconfig/viper.go @@ -33,9 +33,12 @@ func InitViper() { // Remove we dont set env in variables. viper.SetDefault(configconsts.DEVELOPMENT, false) //Remove used in gin.go + viper.SetDefault(configconsts.HTTP_HOST, "0.0.0.0") viper.SetDefault(configconsts.HTTP_PORT, "8080") viper.SetDefault(configconsts.HTTP_TIMEOUT, "15s") + viper.SetDefault(configconsts.HTTP_HEALTH_PORT, "9999") + viper.SetDefault(configconsts.PROFILER_ENABLED, false) viper.SetDefault(configconsts.ENABLE_TRACING, true) viper.SetDefault(configconsts.TRACER_ID, "ror-api") @@ -65,9 +68,20 @@ func InitViper() { viper.SetDefault(configconsts.OPENTELEMETRY_COLLECTOR_ENDPOINT, "opentelemetry-collector:4317") viper.SetDefault(configconsts.HELSEGITLAB_BASE_URL, "https://helsegitlab.nhn.no/api/v4/projects/") - viper.SetDefault(configconsts.HEALTH_ENDPOINT, "0.0.0.0:9999") } func GetRorVersion() rorversion.RorVersion { return RorVersion } + +func GetHTTPEndpoint() string { + return fmt.Sprintf("%s:%s", viper.GetString(configconsts.HTTP_HOST), viper.GetString(configconsts.HTTP_PORT)) +} + +func GetHealthEndpoint() string { + if viper.IsSet(configconsts.HEALTH_ENDPOINT) { + rlog.Info("Using deprecated HEALTH_ENDPOINT configuration. Please use HTTP_HEALTH_HOST and HTTP_HEALTH_PORT instead") + return viper.GetString(configconsts.HEALTH_ENDPOINT) + } + return fmt.Sprintf("%s:%s", viper.GetString(configconsts.HTTP_HEALTH_HOST), viper.GetString(configconsts.HTTP_HEALTH_PORT)) +} diff --git a/internal/webserver/gin.go b/internal/webserver/gin.go index ccff87c..2a634f9 100644 --- a/internal/webserver/gin.go +++ b/internal/webserver/gin.go @@ -1,7 +1,6 @@ package webserver import ( - "fmt" "strings" "github.com/NorskHelsenett/ror-api/internal/apiconfig" @@ -54,11 +53,7 @@ func InitHttpServer() { } _ = router.SetTrustedProxies([]string{"localhost"}) routes.SetupRoutes(router) - if !viper.GetBool(configconsts.DEVELOPMENT) { - rlog.Fatal("router failing", router.Run()) - } else { - rlog.Fatal("router failing", router.Run(fmt.Sprintf("localhost:%s", viper.GetString(configconsts.HTTP_PORT)))) - } + rlog.Fatal("router failing", router.Run(apiconfig.GetHTTPEndpoint())) } func headersMiddleware() gin.HandlerFunc {