Binding middleware for tango
Go to file
Lunny Xiao e1e4a1908b
All checks were successful
checks / check and test (push) Successful in 36s
Use actions instead of drone
2023-04-20 15:21:44 +08:00
.gitea/workflows Use actions instead of drone 2023-04-20 15:21:44 +08:00
LICENSE init 2015-01-24 23:04:48 +08:00
README.md Use actions instead of drone 2023-04-20 15:21:44 +08:00
bind_test.go init 2015-01-24 23:04:48 +08:00
binding.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
common_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
errorhandler_test.go init 2015-01-24 23:04:48 +08:00
errors.go add errors map 2015-04-05 21:13:18 +08:00
errors_test.go init 2015-01-24 23:04:48 +08:00
file_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
form.go init 2015-01-24 23:04:48 +08:00
form_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
go.mod fix import package 2020-02-04 17:19:33 +08:00
go.sum fix import package 2020-02-04 17:19:33 +08:00
json.go init 2015-01-24 23:04:48 +08:00
json_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
misc_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
multipart_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00
validate.go fix import package 2020-02-04 17:19:33 +08:00
validate_test.go update github.com/lunny/tango to gitea.com/lunny/tango 2019-05-20 10:44:00 +08:00

binding

Middlware binding provides request data binding and validation for Tango.

Installation

go get gitea.com/tango/binding

Example

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()
}

Visit /?id=1&name=2 on your browser and you will find output

{1 sss}, []

Getting Help

Credits

This package is forked from macaron-contrib/binding with modifications.

License

This project is under Apache v2 License. See the LICENSE file for the full license text.