package utils import "encoding/json" // interface{} can be any type data func JsonEncode(code int, data interface{}, msg string) ([]byte, error) { result := struct { Code int Data interface{} Msg string }{code, data, msg} return json.Marshal(result) }