mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 03:41:01 +00:00
add healthz endpoint to server
This commit is contained in:
parent
acb6a8b02a
commit
bb8c569249
3 changed files with 29 additions and 0 deletions
|
@ -169,6 +169,9 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
|||
)
|
||||
}
|
||||
|
||||
e.GET("/version", server.Version)
|
||||
e.GET("/healthz", server.Health)
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
|
|
24
server/z.go
Normal file
24
server/z.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"github.com/drone/drone/store"
|
||||
"github.com/drone/drone/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Health endpoint returns a 500 if the server state is unhealthy.
|
||||
func Health(c *gin.Context) {
|
||||
if err := store.FromContext(c).Ping(); err != nil {
|
||||
c.String(500, err.Error())
|
||||
return
|
||||
}
|
||||
c.String(200, "")
|
||||
}
|
||||
|
||||
// Version endpoint returns the server version and build information.
|
||||
func Version(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"source": "https://github.com/drone/drone",
|
||||
"version": version.Version.String(),
|
||||
})
|
||||
}
|
|
@ -139,6 +139,8 @@ type Store interface {
|
|||
TaskList() ([]*model.Task, error)
|
||||
TaskInsert(*model.Task) error
|
||||
TaskDelete(string) error
|
||||
|
||||
Ping() error
|
||||
}
|
||||
|
||||
// GetUser gets a user by unique ID.
|
||||
|
|
Loading…
Reference in a new issue