u
This commit is contained in:
1 parent
01ea998605
commit
d1b1aafc57
9 files changed
+82
-35
No files matched your search
@@ -5,19 +5,25 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 统一响应结构体
|
||||
type ErrorInfo struct {
|
||||
Method string `json:"method,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Stack string `json:"stack,omitempty"`
|
||||
}
|
||||
|
||||
// Result 统一响应结构体
|
||||
type Result struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Error *ErrorInfo `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
// 通用
|
||||
CodeSuccess = "0000" // 成功
|
||||
CodeFail = "0001" // 失败
|
||||
|
||||
// 鉴权 / 登录
|
||||
CodeNoLogin = "1001" // 未登录
|
||||
CodeLoginExpired = "1002" // 登录过期
|
||||
CodeInvalidToken = "1003" // Token 无效
|
||||
@@ -85,6 +91,12 @@ func (b *Builder) Data(data interface{}) *Builder {
|
||||
return b
|
||||
}
|
||||
|
||||
// ErrorInfo 设置错误信息
|
||||
func (b *Builder) ErrorInfo(err *ErrorInfo) *Builder {
|
||||
b.result.Error = err
|
||||
return b
|
||||
}
|
||||
|
||||
// Send 发送响应
|
||||
func (b *Builder) Send() {
|
||||
if b.result.Data == nil {
|
||||
|
||||
Reference in new issue
Block a user