Documentation ¶
Index ¶
- func ClearMsgProcessor()
- func ClearRespProcessor()
- func Marshal(obj interface{}, options ...JsonOption) ([]byte, error)
- func MarshalToString(obj interface{}, options ...JsonOption) (string, error)
- func MustSetUp(messageHook MessageHook, responseHook ResponseHook, messageFiles ...string)
- func Seal(code string, msgArgs ...interface{}) string
- func SealFully(code, message string, data interface{}, msgArgs ...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(ptr interface{}, data []byte) error
- func UnmarshalFromString(ptr interface{}, str string) error
- type JsonOption
- 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 ¶
func Marshal(obj interface{}, options ...JsonOption) ([]byte, error)
Marshal 序列化(可选配置: api && indent).
@param obj 可以为nil || ""
e.g.
(nil) => []byte("null"), nil ("") => []byte("\"\""), nil
func MarshalToString ¶
func MarshalToString(obj interface{}, options ...JsonOption) (string, error)
MarshalToString 序列化为json字符串(可选配置: api && indent).
@param obj 可以为nil || ""
e.g.
(nil) => "null", nil ("") => "\"\"", nil
e.g.1
m := map[string]interface{}{ "a": "0", "b": "1", } str, _ := jsonKit.MarshalToString(m) fmt.Println(str) // {"a":"0","b":"1"} str, _ = jsonKit.MarshalToString(m, jsonKit.WithIndent(" ")) fmt.Println(str) //{ // "a": "0", // "b": "1" //}
func MustSetUp ¶
func MustSetUp(messageHook MessageHook, responseHook ResponseHook, messageFiles ...string)
func SealWithData ¶
func SetMsgHook ¶
func SetMsgHook(hook MessageHook)
func SetRespHook ¶
func SetRespHook(hook ResponseHook)
func SetUp ¶
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 Unmarshal ¶
Unmarshal 反序列化.
@param ptr (1) 不能为nil
(2) 指针类型
@param data 必要条件: len(data) > 0(包含: 不能为nil)
func UnmarshalFromString ¶
UnmarshalFromString 反序列化.
@param ptr (1) 不能为nil
(2) 指针类型
@param str 不能为空字符串("")
Types ¶
type JsonOption ¶
type JsonOption func(opts *jsonOptions)
func WithApi ¶
func WithApi(api jsoniter.API) JsonOption
WithApi
@param api jsoniter.ConfigDefault || jsoniter.ConfigCompatibleWithStandardLibrary || jsoniter.ConfigFastest
func WithIndent ¶
func WithIndent(indent string) JsonOption
WithIndent
@param indent (0) 建议使用 " "(4个空格)
(1) 目前只能是 "" 或 多个空格(不能有其他字符) (2) encoding/json标准库 可以用"\t"
type MessageHook ¶
type Response ¶
type Response struct { Code string `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
Response 响应给前端的json对象.