package network import ( "encoding/json" ) const ( SuccessCode = "6000" // 成功 NeedLogin = "6018" // 登陆过期 ErrorCode = "6020" // 错误 ) type Response struct { Code string Result any 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 any) Response { response := Response{Code: SuccessCode, Result: data} return response } func Page(data any, count int64) Response { response := Response{Code: SuccessCode, Result: map[string]any{ "List": data, "Count": count, }} return response }