mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-11-22 06:23:10 -05:00
Add /ready api to auth
This commit is contained in:
parent
40c13e7ddf
commit
8f0fb42b47
25
auth/main.go
25
auth/main.go
@ -59,7 +59,27 @@ func (v *Validator) Validate(i any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) CheckHealth(c echo.Context) error {
|
func (h *Handler) CheckHealth(c echo.Context) error {
|
||||||
return c.JSON(200, struct{ Status string }{Status: "healthy"})
|
return c.JSON(200, struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
}{Status: "healthy"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handler) CheckReady(c echo.Context) error {
|
||||||
|
_, err := h.rawDb.Exec(c.Request().Context(), "select 1")
|
||||||
|
|
||||||
|
status := "healthy"
|
||||||
|
db := "healthy"
|
||||||
|
ret := 200
|
||||||
|
if err != nil {
|
||||||
|
status = "unhealthy"
|
||||||
|
db = err.Error()
|
||||||
|
ret = 500
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.JSON(ret, struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Database string `json:"database"`
|
||||||
|
}{Status: status, Database: db})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetenvOr(env string, def string) string {
|
func GetenvOr(env string, def string) string {
|
||||||
@ -135,6 +155,7 @@ func OpenDatabase() (*pgxpool.Pool, error) {
|
|||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
db *dbc.Queries
|
db *dbc.Queries
|
||||||
|
rawDb *pgxpool.Pool
|
||||||
config *Configuration
|
config *Configuration
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,6 +232,7 @@ func main() {
|
|||||||
|
|
||||||
h := Handler{
|
h := Handler{
|
||||||
db: dbc.New(db),
|
db: dbc.New(db),
|
||||||
|
rawDb: db,
|
||||||
}
|
}
|
||||||
conf, err := LoadConfiguration(h.db)
|
conf, err := LoadConfiguration(h.db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -228,6 +250,7 @@ func main() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
g.GET("/health", h.CheckHealth)
|
g.GET("/health", h.CheckHealth)
|
||||||
|
g.GET("/ready", h.CheckReady)
|
||||||
|
|
||||||
r.GET("/users", h.ListUsers)
|
r.GET("/users", h.ListUsers)
|
||||||
r.GET("/users/:id", h.GetUser)
|
r.GET("/users/:id", h.GetUser)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user