Documentation
¶
Overview ¶
Package serialization 序列化相关的操作
Index ¶
- Variables
- type Files
- type Locale
- type MarshalFunc
- type Mimetypes
- type Serialization
- func (s *Serialization) Add(m MarshalFunc, u UnmarshalFunc, name ...string) error
- func (s *Serialization) Delete(name string)
- func (s *Serialization) Len() int
- func (s *Serialization) Search(name string) (string, MarshalFunc, UnmarshalFunc)
- func (s *Serialization) SearchFunc(match func(string) bool) (string, MarshalFunc, UnmarshalFunc)
- func (s *Serialization) Set(name string, m MarshalFunc, u UnmarshalFunc)
- type UnmarshalFunc
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = localeutil.Error("unsupported serialization")
ErrUnsupported 返回不支持序列化的错误信息
当一个对象无法被正常的序列化或是反序列化是,返回此错误。
Functions ¶
This section is empty.
Types ¶
type Files ¶
type Files struct {
*Serialization
}
Files 提供针对文件的序列化操作
type Locale ¶
type Locale struct {
// contains filtered or unexported fields
}
Locale 提供了从文件中加载本地化信息的方法
func NewLocale ¶
NewLocale 返回 Locale 实例
f 表示用于加载本地化文件的序列化方法,根据文件扩展名在 f 中查找相应的序列化方法; 加载后的内容被应用在 b 之上。
func (*Locale) LoadFileFS ¶
LoadFileFS 从文件中加载本地化内容
type Mimetypes ¶
type Mimetypes struct {
*Serialization
}
Mimetypes 提供 mimetype 的序列化操作
func (*Mimetypes) MarshalFunc ¶
func (ms *Mimetypes) MarshalFunc(header string) (string, MarshalFunc, bool)
MarshalFunc 从 header 解析出当前请求所需要的 mimetype 名称和对应的解码函数
*/* 或是空值 表示匹配任意内容,一般会选择第一个元素作匹配; xx/* 表示匹配以 xx/ 开头的任意元素,一般会选择 xx/* 开头的第一个元素; xx/ 表示完全匹配以 xx/ 的内容 如果传递的内容如下:
application/json;q=0.9,*/*;q=1
则因为 */* 的 q 值比较高,而返回 */* 匹配的内容
在不完全匹配的情况下,返回值的名称依然是具体名称。
text/*;q=0.9
返回的名称可能是:
text/plain
func (*Mimetypes) UnmarshalFunc ¶
func (ms *Mimetypes) UnmarshalFunc(name string) (UnmarshalFunc, bool)
UnmarshalFunc 查找指定名称的 UnmarshalFunc
type Serialization ¶
type Serialization struct {
// contains filtered or unexported fields
}
Serialization 管理注册的序列化函数
func (*Serialization) Add ¶
func (s *Serialization) Add(m MarshalFunc, u UnmarshalFunc, name ...string) error
Add 添加序列化函数
m 和 u 可以为 nil,表示仅作为一个占位符使用,具体处理要在 ServeHTTP 中另作处理;
name 表示之后用于查找该序列化函数的唯一 ID, 后期用户可以根据 name 从 c.Search 直接查找相应的序列化函数。
func (*Serialization) Search ¶
func (s *Serialization) Search(name string) (string, MarshalFunc, UnmarshalFunc)
func (*Serialization) SearchFunc ¶
func (s *Serialization) SearchFunc(match func(string) bool) (string, MarshalFunc, UnmarshalFunc)
SearchFunc 如果返回的 name 为空,表示没有找到
func (*Serialization) Set ¶
func (s *Serialization) Set(name string, m MarshalFunc, u UnmarshalFunc)
Set 修改或是添加
Directories
¶
Path | Synopsis |
---|---|
Package form 用于处理 www-form-urlencoded 编码 func read(ctx *web.Context) { vals := urls.Values{} ctx.Read(vals) } func write(ctx *web.Context) { vals := urls.Values{} vals.Add("name", "caixw") return web.Object(http.StatusOK, vals, nil) } form 用户可以通过定义 form 标签自定义输出的名称,比如: type Username struct { Name string `form:"name"` Age int } 转换成 form-data 可能是以下样式: name=jjj&age=18 该方式对数据类型有一定限制: 1.
|
Package form 用于处理 www-form-urlencoded 编码 func read(ctx *web.Context) { vals := urls.Values{} ctx.Read(vals) } func write(ctx *web.Context) { vals := urls.Values{} vals.Add("name", "caixw") return web.Object(http.StatusOK, vals, nil) } form 用户可以通过定义 form 标签自定义输出的名称,比如: type Username struct { Name string `form:"name"` Age int } 转换成 form-data 可能是以下样式: name=jjj&age=18 该方式对数据类型有一定限制: 1. |
Package gob 提供 GOB 格式的编解码
|
Package gob 提供 GOB 格式的编解码 |
Package html 提供输出 HTML 内容的解码函数 srv := NewServer() tpl := template.ParseFiles(...) srv.Mimetypes().Add("text/html", html.Marshal, nil) func handle(ctx *web.Context) Responser { return Object(200, html.Tpl(tpl, "index", map[string]interface{}{...}), nil) }
|
Package html 提供输出 HTML 内容的解码函数 srv := NewServer() tpl := template.ParseFiles(...) srv.Mimetypes().Add("text/html", html.Marshal, nil) func handle(ctx *web.Context) Responser { return Object(200, html.Tpl(tpl, "index", map[string]interface{}{...}), nil) } |
Package jsonp JSONP 序列化操作
|
Package jsonp JSONP 序列化操作 |
Package protobuf 提供对 Google protocol buffers 的支持
|
Package protobuf 提供对 Google protocol buffers 的支持 |
Package text 针对文本内容的编解码实现
|
Package text 针对文本内容的编解码实现 |
testobject
Package testobject 用于测试 mimetype 的对象
|
Package testobject 用于测试 mimetype 的对象 |