mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-14 04:29:39 +02:00
- Introduced `NewTestRoute` function to simplify route creation in benchmark tests. - Replaced direct route validation and starting with error handling using `require.NoError`. - Updated server retrieval to use `common.ProxyHTTPAddr` for consistency. - Improved logging for HTTP route addition errors in `AddRoute` method. * fix(tcp): wrap proxy proto listener before acl * refactor(entrypoint): propagate errors from route registration and stream serving * fix(docs): correct swagger and package README
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
entrypoint "github.com/yusing/godoxy/internal/entrypoint/types"
|
|
"github.com/yusing/goutils/apitypes"
|
|
"github.com/yusing/goutils/http/httpheaders"
|
|
"github.com/yusing/goutils/http/websocket"
|
|
)
|
|
|
|
// @x-id "health"
|
|
// @BasePath /api/v1
|
|
// @Summary Get routes health info
|
|
// @Description Get health info by route name
|
|
// @Tags v1,websocket
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} map[string]types.HealthStatusString "Health info by route name"
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Failure 500 {object} apitypes.ErrorResponse
|
|
// @Router /health [get]
|
|
func Health(c *gin.Context) {
|
|
ep := entrypoint.FromCtx(c.Request.Context())
|
|
if ep == nil { // impossible, but just in case
|
|
c.JSON(http.StatusInternalServerError, apitypes.Error("entrypoint not initialized"))
|
|
return
|
|
}
|
|
if httpheaders.IsWebsocket(c.Request.Header) {
|
|
websocket.PeriodicWrite(c, 1*time.Second, func() (any, error) {
|
|
return ep.GetHealthInfoSimple(), nil
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, ep.GetHealthInfoSimple())
|
|
}
|
|
}
|