Files
rideaware-api/pkg/utils/utils.go
2025-11-20 19:00:53 -06:00

16 lines
369 B
Go

package utils
import (
"encoding/json"
"net/http"
)
func JSONResponse(w http.ResponseWriter, code int, payload interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(payload)
}
func JSONError(w http.ResponseWriter, code int, message string) {
JSONResponse(w, code, map[string]string{"error": message})
}