mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 20:12:25 +00:00
- Change package name general_server to gateway - Changing the structure of directories and packages - Adding vendor to the project
23 lines
542 B
Go
23 lines
542 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// writeJSONError writes a JSON error response to the HTTP response writer.
|
|
// It sets the Content-Type to application/json, writes the specified HTTP status code
|
|
func WriteJSONError(w http.ResponseWriter, status int, msg string) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
resp := map[string]any{
|
|
"status": "error",
|
|
"error": msg,
|
|
"code": status,
|
|
}
|
|
if err := json.NewEncoder(w).Encode(resp); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|