1
This commit is contained in:
36
pkg/jsonhelper/jsonhelper.go
Normal file
36
pkg/jsonhelper/jsonhelper.go
Normal file
@ -0,0 +1,36 @@
|
||||
package jsonhelper
|
||||
|
||||
import (
|
||||
"github.com/bytedance/sonic"
|
||||
jsonIterator "github.com/json-iterator/go"
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
var (
|
||||
IJson = jsonIterator.ConfigCompatibleWithStandardLibrary
|
||||
// Marshal is exported by common package.
|
||||
Marshal = IJson.Marshal
|
||||
// Unmarshal is exported by common package.
|
||||
Unmarshal = IJson.Unmarshal
|
||||
// MarshalIndent is exported by common package.
|
||||
MarshalIndent = IJson.MarshalIndent
|
||||
// NewDecoder is exported by common package.
|
||||
NewDecoder = IJson.NewDecoder
|
||||
// NewEncoder is exported by common package.
|
||||
NewEncoder = IJson.NewEncoder
|
||||
|
||||
// MarshalMsgPack msgpack方式序列化
|
||||
MarshalMsgPack = msgpack.Marshal
|
||||
// msgpack方式反序列化
|
||||
UnmarshalMsgPack = msgpack.Unmarshal
|
||||
NewDecoderMsgPack = msgpack.NewDecoder
|
||||
NewEncoderMsgPack = msgpack.NewEncoder
|
||||
)
|
||||
|
||||
func ToJsonString(v interface{}) string {
|
||||
if result, err := sonic.Marshal(v); err == nil {
|
||||
return string(result)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user