Add Go rewrite with Postgres 17 and Dokploy Docker Compose
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"amnezia-share/internal/web"
|
||||
)
|
||||
|
||||
func registerHealth(a *web.App, mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /health", Health(a))
|
||||
}
|
||||
|
||||
// Health reports basic liveness plus a DB ping, mirroring health.php.
|
||||
func Health(a *web.App) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
dbOK := true
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 3*time.Second)
|
||||
defer cancel()
|
||||
if err := a.Pool.Ping(ctx); err != nil {
|
||||
dbOK = false
|
||||
}
|
||||
status := http.StatusOK
|
||||
if !dbOK {
|
||||
status = http.StatusServiceUnavailable
|
||||
}
|
||||
writeJSON(w, status, map[string]any{
|
||||
"ok": dbOK,
|
||||
"db": dbOK,
|
||||
"time": time.Now().UTC().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user