21 lines
501 B
Go
21 lines
501 B
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
func jsonResponse(w http.ResponseWriter, data interface{}, status int) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
json.NewEncoder(w).Encode(data)
|
|
}
|
|
|
|
func jsonError(w http.ResponseWriter, message string, status int) {
|
|
jsonResponse(w, map[string]string{"error": message}, status)
|
|
}
|
|
|
|
func jsonMsg(w http.ResponseWriter, message string) {
|
|
jsonResponse(w, map[string]string{"msg": message}, http.StatusOK)
|
|
}
|