Documentation ¶
Index ¶
- func ClearMsgProcessor()
- func ClearRespProcessor()
- func Marshal(obj interface{}) ([]byte, error)
- func MarshalToString(obj interface{}) (string, error)
- func MarshalToStringWithIndent(obj interface{}) (string, error)
- func MarshalToStringWithJsoniterApi(api jsoniter.API, obj interface{}) (string, error)
- func MarshalWithIndent(obj interface{}) ([]byte, error)
- func MarshalWithJsoniterApi(api jsoniter.API, obj interface{}) ([]byte, error)
- func MustSetUp(messageHook MessageHook, responseHook ResponseHook, messageFiles ...string)
- func Seal(code string, msgArgs ...interface{}) string
- func SealFully(api jsoniter.API, code, message string, data interface{}, ...) (json string, err error)
- func SealWithData(code string, data interface{}, msgArgs ...interface{}) string
- func SetMsgHook(hook MessageHook)
- func SetRespHook(hook ResponseHook)
- func SetUp(msgHook MessageHook, respHook ResponseHook, messageFiles ...string) (err error)
- func Unmarshal(data []byte, ptr interface{}) error
- func UnmarshalFromString(str string, ptr interface{}) error
- func UnmarshalFromStringToMap(str string) (map[string]interface{}, error)
- func UnmarshalToMap(data []byte) (map[string]interface{}, error)
- type MessageHook
- type Response
- type ResponseHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearMsgProcessor ¶
func ClearMsgProcessor()
func ClearRespProcessor ¶
func ClearRespProcessor()
func Marshal ¶
Marshal 序列化.
@param obj 可以为nil || ""
e.g. (nil) => []byte("null"), nil ("") => []byte("\"\""), nil
func MarshalToString ¶
MarshalToString 序列化为字符串.
PS: (1) 缺陷: 多次序列化相同的map实例(length >= 2),返回值可能不同,想解决可以使用 MarshalToStringWithJsoniterApi().
@param obj 可以为nil || ""
e.g. (nil) => "null", nil ("") => "\"\"", nil
func MarshalToStringWithJsoniterApi ¶
MarshalToStringWithJsoniterApi 可以自定义api
@param api 可以为nil,jsoniter.ConfigDefault || jsoniter.ConfigCompatibleWithStandardLibrary || ...
e.g. 如果希望多次序列化同一map实例,返回的json字符串一直,传参api可以为 jsoniter.ConfigCompatibleWithStandardLibrary.
func MarshalWithIndent ¶
func MarshalWithJsoniterApi ¶
MarshalWithJsoniterApi 可以自定义api
func MustSetUp ¶ added in v1.3.11
func MustSetUp(messageHook MessageHook, responseHook ResponseHook, messageFiles ...string)
func SealWithData ¶
func SetMsgHook ¶ added in v1.3.11
func SetMsgHook(hook MessageHook)
func SetRespHook ¶ added in v1.3.11
func SetRespHook(hook ResponseHook)
func SetUp ¶ added in v1.3.11
func SetUp(msgHook MessageHook, respHook ResponseHook, messageFiles ...string) (err error)
SetUp
@param msgProcessor [可以为nil] 对响应结构体中的message进行二开,比如可以加上: 是哪台服务响应的 @param respProcess [可以为nil] 对响应结构体进行二开,以修改序列化为json字符串时的key @param messageFiles [.properties文件] (存储code和msg映射关系的)文件的路径(相对 || 绝对),如果为空则不读取message文件
func UnmarshalFromString ¶
UnmarshalFromString
@param str !!!: 不能为空字符串(""),否则会报错 @param obj 只能为指针(pointer),且不能为nil
Types ¶
type MessageHook ¶
type Response ¶
type Response struct { Code string `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
Response
响应给前端的json对象.