first commit
This commit is contained in:
45
pkg/common/network/response.go
Normal file
45
pkg/common/network/response.go
Normal file
@ -0,0 +1,45 @@
|
||||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
const (
|
||||
SuccessCode = "6000" // 成功
|
||||
NeedLogin = "6018" // 登陆过期
|
||||
ErrorCode = "6020" // 错误
|
||||
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code string
|
||||
Result interface{}
|
||||
Msg string
|
||||
}
|
||||
|
||||
type EmptyResponse struct {
|
||||
}
|
||||
|
||||
func Fail(msg string) Response {
|
||||
response := Response{Code: ErrorCode, Msg: msg}
|
||||
return response
|
||||
}
|
||||
|
||||
func Invalid() string {
|
||||
response := Response{Code: NeedLogin, Msg: "用户身份已过期"}
|
||||
str, _ := json.Marshal(response)
|
||||
return string(str)
|
||||
}
|
||||
|
||||
func Success(data interface{}) Response {
|
||||
response := Response{Code: SuccessCode, Result: data}
|
||||
return response
|
||||
}
|
||||
|
||||
func Page(data interface{}, count int64) Response {
|
||||
response := Response{Code: SuccessCode, Result: map[string]interface{}{
|
||||
"List": data,
|
||||
"Count": count,
|
||||
}}
|
||||
return response
|
||||
}
|
||||
Reference in New Issue
Block a user