- Added a new AGENTS.md file to document the project structure and conventions. - Updated .gitignore to include node_modules and refined cursor rules. - Introduced new backend and frontend components for improved map interactions, including context menus and controls. - Enhanced API composables for better admin and authentication functionalities. - Refactored existing components for cleaner code and improved user experience. - Updated README.md to clarify production asset serving and user setup instructions.
26 lines
667 B
Go
26 lines
667 B
Go
package response
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// JSON writes v as JSON with the given status code.
|
|
func JSON(rw http.ResponseWriter, status int, v any) {
|
|
rw.Header().Set("Content-Type", "application/json")
|
|
rw.WriteHeader(status)
|
|
if v != nil {
|
|
_ = json.NewEncoder(rw).Encode(v)
|
|
}
|
|
}
|
|
|
|
// JSONError writes an error response in standard format: {"error": "message", "code": "CODE"}.
|
|
func JSONError(rw http.ResponseWriter, status int, msg string, code string) {
|
|
rw.Header().Set("Content-Type", "application/json")
|
|
rw.WriteHeader(status)
|
|
_ = json.NewEncoder(rw).Encode(map[string]string{
|
|
"error": msg,
|
|
"code": code,
|
|
})
|
|
}
|