1 Star 2 Fork 0

api-go/iris

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
transcoding.go 1.30 KB
一键复制 编辑 原始数据 按行查看 历史
package sessions
import "encoding/json"
type (
// Marshaler is the common marshaler interface, used by transcoder.
Marshaler interface {
Marshal(interface{}) ([]byte, error)
}
// Unmarshaler is the common unmarshaler interface, used by transcoder.
Unmarshaler interface {
Unmarshal([]byte, interface{}) error
}
// Transcoder is the interface that transcoders should implement, it includes just the `Marshaler` and the `Unmarshaler`.
Transcoder interface {
Marshaler
Unmarshaler
}
)
// DefaultTranscoder is the default transcoder across databases, it's the JSON by default.
// Change it if you want a different serialization/deserialization inside your session databases (when `UseDatabase` is used).
var DefaultTranscoder Transcoder = defaultTranscoder{}
type defaultTranscoder struct{}
func (d defaultTranscoder) Marshal(value interface{}) ([]byte, error) {
if tr, ok := value.(Marshaler); ok {
return tr.Marshal(value)
}
if jsonM, ok := value.(json.Marshaler); ok {
return jsonM.MarshalJSON()
}
return json.Marshal(value)
}
func (d defaultTranscoder) Unmarshal(b []byte, outPtr interface{}) error {
if tr, ok := outPtr.(Unmarshaler); ok {
return tr.Unmarshal(b, outPtr)
}
if jsonUM, ok := outPtr.(json.Unmarshaler); ok {
return jsonUM.UnmarshalJSON(b)
}
return json.Unmarshal(b, outPtr)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/netscript/iris.git
git@gitee.com:netscript/iris.git
netscript
iris
iris
v11.1.1

搜索帮助