package handler import ( "net/http" "github.com/zeromicro/go-zero/rest/httpx" ) // 统一响应结构:{ code, message, data } type Response struct { Code int `json:"code"` Message string `json:"message"` Data any `json:"data,omitempty"` } func ok(w http.ResponseWriter, data any) { httpx.WriteJson(w, http.StatusOK, Response{Code: 0, Message: "ok", Data: data}) } func fail(w http.ResponseWriter, httpStatus int, message string) { httpx.WriteJson(w, httpStatus, Response{Code: -1, Message: message}) } func failCode(w http.ResponseWriter, httpStatus, code int, message string) { httpx.WriteJson(w, httpStatus, Response{Code: code, Message: message}) }