mirror of
https://github.com/EZ-Api/ez-api.git
synced 2026-01-13 17:47:51 +00:00
feat(auth): implement master key authentication system with child key issuance
Add admin and master authentication layers with JWT support. Replace direct key creation with hierarchical master/child key system. Update database schema to support master accounts with configurable limits and epoch-based key revocation. Add health check endpoint with system status monitoring. BREAKING CHANGE: Removed direct POST /keys endpoint in favor of master-based key issuance through /v1/tokens. Database migration requires dropping old User table and creating Master table with new relationships.
This commit is contained in:
56
internal/service/health.go
Normal file
56
internal/service/health.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type HealthCheckService struct {
|
||||
db *gorm.DB
|
||||
rdb *redis.Client
|
||||
}
|
||||
|
||||
func NewHealthCheckService(db *gorm.DB, rdb *redis.Client) *HealthCheckService {
|
||||
return &HealthCheckService{
|
||||
db: db,
|
||||
rdb: rdb,
|
||||
}
|
||||
}
|
||||
|
||||
type HealthStatus struct {
|
||||
Status string `json:"status"`
|
||||
Database string `json:"database"`
|
||||
Redis string `json:"redis"`
|
||||
Uptime string `json:"uptime"`
|
||||
}
|
||||
|
||||
var startTime = time.Now()
|
||||
|
||||
func (s *HealthCheckService) Check(ctx context.Context) HealthStatus {
|
||||
status := HealthStatus{
|
||||
Status: "ok",
|
||||
Database: "up",
|
||||
Redis: "up",
|
||||
Uptime: time.Since(startTime).String(),
|
||||
}
|
||||
|
||||
sqlDB, err := s.db.DB()
|
||||
if err != nil || sqlDB.Ping() != nil {
|
||||
status.Database = "down"
|
||||
status.Status = "degraded"
|
||||
}
|
||||
|
||||
if s.rdb.Ping(ctx).Err() != nil {
|
||||
status.Redis = "down"
|
||||
status.Status = "degraded"
|
||||
}
|
||||
|
||||
if status.Database == "down" && status.Redis == "down" {
|
||||
status.Status = "down"
|
||||
}
|
||||
|
||||
return status
|
||||
}
|
||||
Reference in New Issue
Block a user