package server import "encoding/json" type RestResult struct { Code int `json:"code"` Message string `json:"message"` Error string `json:"error"` Data interface{} `json:"data"` } var ResultSuccess = RestResult{ Code: 200, Message: "success", Data: nil, } var ResultError = RestResult{ Code: 500, Message: "error", Error: "error", } func NewErrorResult(err error) []byte { result := ResultError result.Error = err.Error() ret, _ := json.Marshal(result) return ret } func NewSuccessResult(data interface{}) []byte { result := ResultSuccess result.Data = data ret, _ := json.Marshal(result) return ret }