27 lines
737 B
Go
27 lines
737 B
Go
package handler
|
||||
|
|
|
|||
|
|
import (
|
|||
|
|
"net/http"
|
|||
|
|
|
|||
|
|
"github.com/zeromicro/go-zero/rest/httpx"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
// 统一响应结构:{ code, message, data }(风格仿 bj_power_wms/internal/handler/response.go)
|
|||
|
|
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})
|
|||
|
|
}
|