package json type Json struct { Code int `json:"code"` Data interface{} `json:"data"` Msg string `json:"msg"` Status bool `json:"status"` } func GetDefaultJsonSuccessResponse() *Json { return &Json{ Code: 0, Data: nil, Msg: "ok", Status: true, } } func GetDefaultJsonFailedResponse() *Json { return &Json{ Code: 1, Data: nil, Msg: "unknow", Status: false, } } func New(status bool, code int, msg string, data ...interface{}) *Json { if len(data) > 0 { return &Json{ Code: code, Data: data[0], Msg: msg, Status: status, } } else { return &Json{ Code: code, Data: nil, Msg: msg, Status: status, } } }