Merged in feature/healthmove (pull request #165)

Move health endpoint from OpenAPI spec to direct implementation

* Move health endpoint from OpenAPI spec to direct implementation

- Removed HealthService tag from OpenAPI spec
- Removed /health path from OpenAPI spec
- Removed health.go and health_test.go files from api/queryAPI
- Added direct health endpoint in internal/server/api/listener.go
- Updated validator options to skip validation for the /health endpoint
- Added test for health endpoint in internal/server/api/listener_test.go
- Regenerated API code from the updated OpenAPI spec
This commit is contained in:
Michael McGuinness
2025-06-10 20:32:10 +00:00
parent e544f08505
commit d4a65ccf78
11 changed files with 280 additions and 423 deletions
+8 -1
View File
@@ -5,6 +5,7 @@ import (
"errors"
"log/slog"
"net"
"net/http"
"os"
"strconv"
"time"
@@ -212,6 +213,11 @@ func New(ctx context.Context, cfg Config) (*Server, error) {
e.Use(echoprometheus.NewMiddleware("echo"))
e.GET("/metrics", echoprometheus.NewHandler())
// Health endpoint
e.GET("/health", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
e.Use(getSlogCustomEchoMiddleware(cfg.GetLogger()))
e.Use(middleware.Recover())
e.Use(middleware.CORS())
@@ -247,7 +253,8 @@ func setOapi(e *echo.Echo, opnapi *openapi3.T) error {
validatorOptions := &oapimiddleware.Options{
Skipper: func(c echo.Context) bool {
return len(c.Path()) >= 8 && (c.Path()[:8] == "/swagger" ||
c.Path()[:8] == "/metrics")
c.Path()[:8] == "/metrics") ||
c.Path() == "/health"
},
Options: openapi3filter.Options{
AuthenticationFunc: openapi3filter.NoopAuthenticationFunc,
+23
View File
@@ -82,6 +82,29 @@ func TestGetRouter(t *testing.T) {
assert.Equal(t, r, c.Router)
}
func TestHealthEndpoint(t *testing.T) {
// Create a new Echo instance
e := echo.New()
// Register health endpoint
e.GET("/health", func(c echo.Context) error {
return c.NoContent(http.StatusOK)
})
// Create a request to the health endpoint
req := httptest.NewRequest(http.MethodGet, "/health", nil)
rec := httptest.NewRecorder()
// Serve the request
e.ServeHTTP(rec, req)
// Assert the response status code
assert.Equal(t, http.StatusOK, rec.Code)
// Assert the response body is empty
assert.Empty(t, rec.Body.String())
}
func TestGetSlogCustomEchoMiddleware(t *testing.T) {
l := &logger.TestLogger{
T: t,