初始化2
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// Response 统一响应结构:{ 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})
|
||||
}
|
||||
Reference in New Issue
Block a user