mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Update api docs
This commit is contained in:
@@ -7,6 +7,11 @@ import (
|
||||
"novamd/internal/storage"
|
||||
)
|
||||
|
||||
// ErrorResponse is a generic error response
|
||||
type ErrorResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// Handler provides common functionality for all handlers
|
||||
type Handler struct {
|
||||
DB db.Database
|
||||
@@ -25,6 +30,12 @@ func NewHandler(db db.Database, s storage.Manager) *Handler {
|
||||
func respondJSON(w http.ResponseWriter, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if err := json.NewEncoder(w).Encode(data); err != nil {
|
||||
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
respondError(w, "Failed to encode response", http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// respondError is a helper to send error responses
|
||||
func respondError(w http.ResponseWriter, message string, code int) {
|
||||
w.WriteHeader(code)
|
||||
respondJSON(w, ErrorResponse{Message: message})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user