backup: pre-hardening baseline
This commit is contained in:
commit
9e4c612dcb
57 changed files with 10393 additions and 0 deletions
53
backend/internal/api/handlers/health.go
Normal file
53
backend/internal/api/handlers/health.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type HealthHandler struct {
|
||||
startTime time.Time
|
||||
configDir string
|
||||
}
|
||||
|
||||
func NewHealthHandler() *HealthHandler {
|
||||
return &HealthHandler{startTime: time.Now()}
|
||||
}
|
||||
|
||||
func (h *HealthHandler) SetConfigDir(dir string) {
|
||||
h.configDir = dir
|
||||
}
|
||||
|
||||
func (h *HealthHandler) Health(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ok",
|
||||
"uptime": time.Since(h.startTime).String(),
|
||||
"timestamp": time.Now().Format(time.RFC3339),
|
||||
"version": "dev",
|
||||
})
|
||||
}
|
||||
|
||||
func (h *HealthHandler) Ready(c *gin.Context) {
|
||||
configStatus := "ok"
|
||||
if h.configDir != "" {
|
||||
if _, err := os.Stat(h.configDir); err != nil {
|
||||
configStatus = "error: " + err.Error()
|
||||
} else if f, err := os.CreateTemp(h.configDir, ".writetest"); err != nil {
|
||||
configStatus = "not writable: " + err.Error()
|
||||
} else {
|
||||
f.Close()
|
||||
os.Remove(f.Name())
|
||||
}
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": "ready",
|
||||
"checks": gin.H{
|
||||
"database": "ok",
|
||||
"traefik": "ok",
|
||||
"configDir": configStatus,
|
||||
},
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue