Files
butterfliu/internal/controller/response.go
lzw-723 a8d976b97e
All checks were successful
Go CI / test-and-build (push) Successful in 43s
清理代码库
2026-04-06 13:17:57 +08:00

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)
}