mirror of https://github.com/gofiber/fiber.git
Rename default endpoints
parent
a6572aff7a
commit
8f5b5f4695
|
@ -45,32 +45,38 @@ After you initiate your [Fiber](https://github.com/gofiber/fiber) app, you can u
|
||||||
|
|
||||||
```go
|
```go
|
||||||
// Provide a minimal config for liveness check
|
// Provide a minimal config for liveness check
|
||||||
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.New())
|
app.Get(healthcheck.LivenessEndpoint, healthcheck.New())
|
||||||
|
|
||||||
// Provide a minimal config for readiness check
|
// Provide a minimal config for readiness check
|
||||||
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.New())
|
app.Get(healthcheck.ReadinessEndpoint, healthcheck.New())
|
||||||
|
|
||||||
// Provide a minimal config for startup check
|
// Provide a minimal config for startup check
|
||||||
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.New())
|
app.Get(healthcheck.StartupEndpoint, healthcheck.New())
|
||||||
|
|
||||||
// Provide a minimal config for check with custom endpoint
|
// Provide a minimal config for check with custom endpoint
|
||||||
app.Get("/live", healthcheck.New())
|
app.Get("/live", healthcheck.New())
|
||||||
|
|
||||||
// Or extend your config for customization
|
// Or extend your config for customization
|
||||||
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.New(healthcheck.Config{
|
app.Get(healthcheck.LivenessEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// And it works the same for readiness, just change the route
|
// And it works the same for readiness, just change the route
|
||||||
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.New(healthcheck.Config{
|
app.Get(healthcheck.ReadinessEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// And it works the same for startup, just change the route
|
// And it works the same for startup, just change the route
|
||||||
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.New(healthcheck.Config{
|
app.Get(healthcheck.StartupEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// With a custom route and custom probe
|
// With a custom route and custom probe
|
||||||
app.Get("/live", healthcheck.New(healthcheck.Config{
|
app.Get("/live", healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
|
@ -81,7 +87,7 @@ app.Get("/live", healthcheck.New(healthcheck.Config{
|
||||||
// It can also be used with app.All, although it will only respond to requests with the GET method
|
// It can also be used with app.All, although it will only respond to requests with the GET method
|
||||||
// in case of calling the route with any method which isn't GET, the return will be 404 Not Found when app.All is used
|
// in case of calling the route with any method which isn't GET, the return will be 404 Not Found when app.All is used
|
||||||
// and 405 Method Not Allowed when app.Get is used
|
// and 405 Method Not Allowed when app.Get is used
|
||||||
app.All(healthcheck.DefaultReadinessEndpoint, healthcheck.New(healthcheck.Config{
|
app.All(healthcheck.ReadinessEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
@ -117,7 +123,7 @@ type Config struct {
|
||||||
The default configuration used by this middleware is defined as follows:
|
The default configuration used by this middleware is defined as follows:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func defaultProbe(c fiber.Ctx) bool { return true }
|
func defaultProbe(_ fiber.Ctx) bool { return true }
|
||||||
|
|
||||||
var ConfigDefault = Config{
|
var ConfigDefault = Config{
|
||||||
Probe: defaultProbe,
|
Probe: defaultProbe,
|
||||||
|
|
|
@ -1564,18 +1564,18 @@ With the new version, each health check endpoint is configured separately, allow
|
||||||
// after
|
// after
|
||||||
|
|
||||||
// Default liveness endpoint configuration
|
// Default liveness endpoint configuration
|
||||||
app.Get(healthcheck.DefaultLivenessEndpoint, healthcheck.New(healthcheck.Config{
|
app.Get(healthcheck.LivenessEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Default readiness endpoint configuration
|
// Default readiness endpoint configuration
|
||||||
app.Get(healthcheck.DefaultReadinessEndpoint, healthcheck.New())
|
app.Get(healthcheck.ReadinessEndpoint, healthcheck.New())
|
||||||
|
|
||||||
// New default startup endpoint configuration
|
// New default startup endpoint configuration
|
||||||
// Default endpoint is /startupz
|
// Default endpoint is /startupz
|
||||||
app.Get(healthcheck.DefaultStartupEndpoint, healthcheck.New(healthcheck.Config{
|
app.Get(healthcheck.StartupEndpoint, healthcheck.New(healthcheck.Config{
|
||||||
Probe: func(c fiber.Ctx) bool {
|
Probe: func(c fiber.Ctx) bool {
|
||||||
return serviceA.Ready() && serviceB.Ready() && ...
|
return serviceA.Ready() && serviceB.Ready() && ...
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,12 +22,12 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultLivenessEndpoint = "/livez"
|
LivenessEndpoint = "/livez"
|
||||||
DefaultReadinessEndpoint = "/readyz"
|
ReadinessEndpoint = "/readyz"
|
||||||
DefaultStartupEndpoint = "/startupz"
|
StartupEndpoint = "/startupz"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultProbe(c fiber.Ctx) bool { return true }
|
func defaultProbe(_ fiber.Ctx) bool { return true }
|
||||||
|
|
||||||
func defaultConfig(config ...Config) Config {
|
func defaultConfig(config ...Config) Config {
|
||||||
if len(config) < 1 {
|
if len(config) < 1 {
|
||||||
|
|
|
@ -34,9 +34,9 @@ func Test_HealthCheck_Strict_Routing_Default(t *testing.T) {
|
||||||
StrictRouting: true,
|
StrictRouting: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get(DefaultLivenessEndpoint, New())
|
app.Get(LivenessEndpoint, New())
|
||||||
app.Get(DefaultReadinessEndpoint, New())
|
app.Get(ReadinessEndpoint, New())
|
||||||
app.Get(DefaultStartupEndpoint, New())
|
app.Get(StartupEndpoint, New())
|
||||||
|
|
||||||
shouldGiveOK(t, app, "/readyz")
|
shouldGiveOK(t, app, "/readyz")
|
||||||
shouldGiveOK(t, app, "/livez")
|
shouldGiveOK(t, app, "/livez")
|
||||||
|
@ -53,9 +53,9 @@ func Test_HealthCheck_Default(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
app.Get(DefaultLivenessEndpoint, New())
|
app.Get(LivenessEndpoint, New())
|
||||||
app.Get(DefaultReadinessEndpoint, New())
|
app.Get(ReadinessEndpoint, New())
|
||||||
app.Get(DefaultStartupEndpoint, New())
|
app.Get(StartupEndpoint, New())
|
||||||
|
|
||||||
shouldGiveOK(t, app, "/readyz")
|
shouldGiveOK(t, app, "/readyz")
|
||||||
shouldGiveOK(t, app, "/livez")
|
shouldGiveOK(t, app, "/livez")
|
||||||
|
@ -88,7 +88,7 @@ func Test_HealthCheck_Custom(t *testing.T) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
app.Get(DefaultStartupEndpoint, New(Config{
|
app.Get(StartupEndpoint, New(Config{
|
||||||
Probe: func(_ fiber.Ctx) bool {
|
Probe: func(_ fiber.Ctx) bool {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
@ -170,9 +170,9 @@ func Test_HealthCheck_Next(t *testing.T) {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
app.Get(DefaultLivenessEndpoint, checker)
|
app.Get(LivenessEndpoint, checker)
|
||||||
app.Get(DefaultReadinessEndpoint, checker)
|
app.Get(ReadinessEndpoint, checker)
|
||||||
app.Get(DefaultStartupEndpoint, checker)
|
app.Get(StartupEndpoint, checker)
|
||||||
|
|
||||||
// This should give not found since there are no other handlers to execute
|
// This should give not found since there are no other handlers to execute
|
||||||
// so it's like the route isn't defined at all
|
// so it's like the route isn't defined at all
|
||||||
|
@ -184,9 +184,9 @@ func Test_HealthCheck_Next(t *testing.T) {
|
||||||
func Benchmark_HealthCheck(b *testing.B) {
|
func Benchmark_HealthCheck(b *testing.B) {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Get(DefaultLivenessEndpoint, New())
|
app.Get(LivenessEndpoint, New())
|
||||||
app.Get(DefaultReadinessEndpoint, New())
|
app.Get(ReadinessEndpoint, New())
|
||||||
app.Get(DefaultStartupEndpoint, New())
|
app.Get(StartupEndpoint, New())
|
||||||
|
|
||||||
h := app.Handler()
|
h := app.Handler()
|
||||||
fctx := &fasthttp.RequestCtx{}
|
fctx := &fasthttp.RequestCtx{}
|
||||||
|
@ -206,9 +206,9 @@ func Benchmark_HealthCheck(b *testing.B) {
|
||||||
func Benchmark_HealthCheck_Parallel(b *testing.B) {
|
func Benchmark_HealthCheck_Parallel(b *testing.B) {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
|
|
||||||
app.Get(DefaultLivenessEndpoint, New())
|
app.Get(LivenessEndpoint, New())
|
||||||
app.Get(DefaultReadinessEndpoint, New())
|
app.Get(ReadinessEndpoint, New())
|
||||||
app.Get(DefaultStartupEndpoint, New())
|
app.Get(StartupEndpoint, New())
|
||||||
|
|
||||||
h := app.Handler()
|
h := app.Handler()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue