Documentation
¶
Overview ¶
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")
ctx.Render(http.StatusOK, vals, nil)
}
form
用户可以通过定义 form 标签自定义输出的名称,比如:
type Username struct {
Name string `form:"name"`
Age int
}
转换成 form-data 可能是以下样式:
name=jjj&age=18
该方式对数据类型有一定限制:
- 如果是 map 类型,要求键名类型必须为 string;
- 如果是 array 或是 slice,则要求元素类型必须是 go 的基本数据类型,不能是 struct 类型;
接口
对于复杂类型,用户可以自定义实现 Marshaler 和 Unmarshaler 接口进行编解码, 其功能与用户与 encoding/json 中的 Marshaler 和 Unmarshaler 接口相似。
Index ¶
Constants ¶
View Source
const Mimetype = "application/x-www-form-urlencoded"
Mimetype 当前编码的媒体类型
View Source
const Tag = "form"
Tag 在 struct tag 中的标签名称
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Unmarshaler ¶
Unmarshaler 将 form 类型转换成一个对象
Click to show internal directories.
Click to hide internal directories.