diff options
author | Robby Zambito <contact@robbyzambito.me> | 2025-08-07 02:48:12 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2025-08-07 20:22:47 -0400 |
commit | 7926e31163bf1752d0c876762e11f79a0952180f (patch) | |
tree | 21ad5c11ee2c4e25f6c5948874092eea7c8cc258 | |
parent | 53a699d2b32a3d7a5268de7ac5b9c6daa0fc3975 (diff) |
Stub out status and contact API handlers
-rw-r--r-- | internal/api/handlers.go | 81 | ||||
-rw-r--r-- | main.go | 19 |
2 files changed, 91 insertions, 9 deletions
diff --git a/internal/api/handlers.go b/internal/api/handlers.go index 45354aa..194401d 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -73,6 +73,87 @@ func CreateLoginHandler(logs *[LogLength]string, n *int, logChan chan string) ht } } +func StatusHandler(w http.ResponseWriter, r *http.Request) { + type response struct { + Status string `json:"status"` + Description string `json:"description"` + Uptime float64 `json:"uptime"` + ResponseTime int `json:"responseTime"` + ActiveIncidents int `json:"activeIncidents"` + ScheduledMaintenance int `json:"scheduledMaintenance"` + } +} + +func StatusServicesHandler(w http.ResponseWriter, r *http.Request) { + type service struct { + Id string `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Icon string `json:"icon"` + Status string `json:"status"` + ResponseTime int `json:"responseTime"` + Uptime float64 `json:"uptime"` + } + + var response []service + _ = response +} + +func StatusMetricsHandler(w http.ResponseWriter, r *http.Request) { + type response struct { + Uptime float64 `json:"uptime"` + ResponseTime int `json:"responseTime"` + RequestVolume int `json:"requestVolume"` + ErrorRate float64 `json:"errorRate"` + } +} + +func StatusIncidentsHandler(w http.ResponseWriter, r *http.Request) { + type incident struct { + Id string `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + Status string `json:"status"` + Severity string `json:"severity"` + StartTime time.Time `json:"startTime"` + AffectedServices []string `json:"affectedServices"` + } + var response []incident + _ = response +} + +func StatusMaintenanceHandler(w http.ResponseWriter, r *http.Request) { + type event struct { + Id string `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + StartTime time.Time `json:"startTime"` + EndTime time.Time `json:"endTime"` + AffectedServices []string `json:"affectedServices"` + } + var response []event + _ = response +} + +func StatusUptimeHandler(w http.ResponseWriter, r *http.Request) { + type event struct { + Date time.Time `json:"date"` + Uptime float64 `json:"uptime"` + } + var response []event + _ = response +} + +// TODO: SUBSCRIBE TO EMAILS +func StatusSubscribeHandler(w http.ResponseWriter, r *http.Request) { + +} + +// TODO: CONTACT HANDLER +func ContactHandler(w http.ResponseWriter, r *http.Request) { + +} + func redactIP(input string) string { ipRegex := `\b(?:\d{1,3}\.){3}\d{1,3}\b` re := regexp.MustCompile(ipRegex) @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "net/http" - "time" "git.robbyzambito.me/snorvik/internal/api" ) @@ -12,14 +11,6 @@ import ( // Example: // curl 'http://localhost:8080/api/v1/auth/login' -X POST -H 'Content-Type: application/json' --data-raw $'{}}\n{"king": "key"' -type loginAttemptLog struct { - Email string `json:"email"` - Password string `json:"password"` - LoginTime time.Time `json:"loginTime"` - Success bool `json:"success"` - RememberMe bool `json:"rememberMe"` -} - func main() { var logs [api.LogLength]string n := 0 @@ -37,6 +28,16 @@ func main() { fmt.Fprintf(w, king) }) + http.HandleFunc("/api/v1/status", api.StatusHandler) + http.HandleFunc("/api/v1/status/services", api.StatusServicesHandler) + http.HandleFunc("/api/v1/status/metrics", api.StatusMetricsHandler) + http.HandleFunc("/api/v1/status/incidents", api.StatusIncidentsHandler) + http.HandleFunc("/api/v1/status/maintenance", api.StatusMaintenanceHandler) + http.HandleFunc("/api/v1/status/uptime", api.StatusUptimeHandler) + http.HandleFunc("/api/v1/status/subscribe", api.StatusSubscribeHandler) + + http.HandleFunc("/api/v1/contact", api.ContactHandler) + // Start the server on port 8080 fmt.Println("Server is listening on port 8080...") err := http.ListenAndServe(":8080", nil) |