Files
bj_power/bj_power_wms/internal/handler/response.go
T
2026-08-28 15:06:01 +08:00

27 lines
680 B
Go

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