16 lines
369 B
Go
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})
|
|
} |