46 lines
819 B
Go
46 lines
819 B
Go
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
|
|
}
|