| 12345678910111213141516171819202122232425262728293031323334 |
- package micro
- const (
- SUCCESS = 200
- FAIL = 500
- ERROR = 400
- UNAUTHORIZED = 401
- )
- type Response struct {
- Code int64 `json:"code"`
- Message string `json:"message"`
- Data any `json:"data"`
- }
- // Success 成功
- func Success(data interface{}) Response {
- return Response{SUCCESS, "success", data}
- }
- // Fail 失败
- func Fail(msg string) Response {
- return Response{FAIL, msg, ""}
- }
- // Error 错误
- func Error(msg string) Response {
- return Response{ERROR, msg, ""}
- }
- // Unauthorized 认证失败
- func Unauthorized(msg string, data interface{}) Response {
- return Response{UNAUTHORIZED, msg, data}
- }
|