diff --git a/handlers/health.go b/handlers/health.go index de14ce5..e52abb7 100644 --- a/handlers/health.go +++ b/handlers/health.go @@ -2,20 +2,19 @@ package handlers import ( "authentication/db" + "authentication/helper" "authentication/models" "authentication/redisclient" "context" - "encoding/json" "net/http" "time" ) func HealthHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(models.HealthResponse{ - Status: "ok", - }) + response := models.HealthResponse{ + Status: "AuthN Capy!", + } + helper.RespondWithJSON(w, http.StatusOK, response) } // ReadyHandler checks if the service is ready to handle requests @@ -62,15 +61,15 @@ func ReadyHandler(w http.ResponseWriter, r *http.Request) { allHealthy = false } - status := "ready" + status := "Capy!" statusCode := http.StatusOK if !allHealthy { - status = "not_ready" + status = "not Capy!" statusCode = http.StatusServiceUnavailable } w.WriteHeader(statusCode) - json.NewEncoder(w).Encode(models.HealthResponse{ + helper.RespondWithJSON(w, statusCode, models.HealthResponse{ Status: status, Services: services, }) diff --git a/handlers/jwt.go b/handlers/jwt.go index 13afa31..29808c2 100644 --- a/handlers/jwt.go +++ b/handlers/jwt.go @@ -51,7 +51,7 @@ func init() { keyPath = "rsa/psa.gov.ph.key" } - keyData, err := os.ReadFile(keyPath) + keyData, err := os.ReadFile(keyPath) // #nosec G304 if err != nil { if isTestEnvironment() { log.Printf("Failed to read RSA private key file at %s, generating test key: %v", keyPath, err) diff --git a/middleware/csrf.go b/middleware/csrf.go index 6ac6bc9..82515db 100644 --- a/middleware/csrf.go +++ b/middleware/csrf.go @@ -11,7 +11,7 @@ import ( ) const ( - csrfTokenHeader = "X-CSRF-Token" + csrfTokenHeader = "X-CSRF-Token" // #nosec G101 csrfCookieName = "csrf_token" csrfTokenLength = 32 csrfTokenTTL = 24 * time.Hour