Page:
ZH_Binding
Pages
Actions
Basicauth
Binding
Captcha
Compress
Context
Debug
Dispatch
ErrHandler
Events
Flash
Forms
Group
Handler
Home
Injection
Logger
Params
QuickStart
Recovery
Renders
Return
Router
Session
Static
Tango
Tpongo2
Xsrf
ZH_Actions
ZH_Basicauth
ZH_Binding
ZH_Captcha
ZH_Compress
ZH_Context
ZH_Debug
ZH_Dispatch
ZH_ErrHandler
ZH_Events
ZH_Flash
ZH_Forms
ZH_Group
ZH_HOME
ZH_Handler
ZH_Injection
ZH_Logger
ZH_Params
ZH_Recovery
ZH_Renders
ZH_Return
ZH_Router
ZH_Session
ZH_Static
ZH_Tango
ZH_Tpongo2
ZH_Xsrf
2
ZH_Binding
Lunny Xiao edited this page 2019-11-27 09:08:08 +08:00
Binding中间件提供了自动提取请求参数到结构体的映射和要求检查。他是一个 Tango 的中间件。
安装
go get gitea.com/tango/binding
示例
import (
"gitea.com/lunny/tango"
"gitea.com/tango/binding"
)
type Action struct {
binding.Binder
}
type MyStruct struct {
Id int64
Name string
}
func (a *Action) Get() string {
var mystruct MyStruct
errs := a.Bind(&mystruct)
return fmt.Sprintf("%v, %v", mystruct, errs)
}
func main() {
t := tango.Classic()
t.Use(binding.Bind())
t.Get("/", new(Action))
t.Run()
}
访问 /?id=1&name=2
你将会查看到输入如下:
{1 sss}, []