代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。