30 lines
752 B
Go
30 lines
752 B
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type response map[string]any
|
|
|
|
func Health(w http.ResponseWriter, r *http.Request) {
|
|
writeJSON(w, http.StatusOK, response{"status": "ok"})
|
|
}
|
|
|
|
func ListUsers(w http.ResponseWriter, r *http.Request) {
|
|
writeJSON(w, http.StatusOK, response{"users": []response{}})
|
|
}
|
|
|
|
func CreateUser(w http.ResponseWriter, r *http.Request) {
|
|
writeJSON(w, http.StatusCreated, response{"status": "created"})
|
|
}
|
|
|
|
func writeJSON(w http.ResponseWriter, status int, payload any) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
|
|
if err := json.NewEncoder(w).Encode(payload); err != nil {
|
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
|
}
|
|
}
|