mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
add context.ReadURL - relative to #1659
This commit is contained in:
commit
637f7aeea7
|
@ -310,6 +310,7 @@ var dirOpts = iris.DirOptions{
|
|||
|
||||
## New Context Methods
|
||||
|
||||
- `Context.ReadURL(ptr interface{}) error` shortcut of `ReadParams` and `ReadQuery`. Binds URL dynamic path parameters and URL query parameters to the given "ptr" pointer of a struct value.
|
||||
- `Context.SetUser(User)` and `Context.User() User` to store and retrieve an authenticated client. Read more [here](https://github.com/iris-contrib/middleware/issues/63).
|
||||
- `Context.SetLogoutFunc(fn interface{}, persistenceArgs ...interface{})` and `Logout(args ...interface{}) error` methods to allow different kind of auth middlewares to be able to set a "logout" a user/client feature with a single function, the route handler may not be aware of the implementation of the authentication used.
|
||||
- `Context.SetFunc(name string, fn interface{}, persistenceArgs ...interface{})` and `Context.CallFunc(name string, args ...interface{}) ([]reflect.Value, error)` to allow middlewares to share functions dynamically when the type of the function is not predictable, see the [example](https://github.com/kataras/iris/tree/master/_examples/routing/writing-a-middleware/share-funcs) for more.
|
||||
|
|
|
@ -31,6 +31,7 @@ With your help, we can improve Open Source web development for everyone!
|
|||
> Donations from **China** are now accepted!
|
||||
|
||||
<p>
|
||||
<a href="https://github.com/KevinZhouRafael"><img src="https://avatars1.githubusercontent.com/u/16298046?v=4" alt ="Kevin Zhou" title="KevinZhouRafael" with="75" style="width:75px;max-width:75px;height:75px" height="75" /></a>
|
||||
<a href="https://github.com/mizzlespot"><img src="https://avatars1.githubusercontent.com/u/2654538?v=4" alt ="Jasper" title="mizzlespot" with="75" style="width:75px;max-width:75px;height:75px" height="75" /></a>
|
||||
<a href="https://github.com/wiener01mu"><img src="https://avatars1.githubusercontent.com/u/41128011?v=4" alt ="Simranjit Singh" title="wiener01mu" with="75" style="width:75px;max-width:75px;height:75px" height="75" /></a>
|
||||
<a href="https://github.com/theantichris"><img src="https://avatars1.githubusercontent.com/u/1486502?v=4" alt ="Christopher Lamm" title="theantichris" with="75" style="width:75px;max-width:75px;height:75px" height="75" /></a>
|
||||
|
|
|
@ -2359,6 +2359,30 @@ func (ctx *Context) ReadParams(ptr interface{}) error {
|
|||
return ctx.app.Validate(ptr)
|
||||
}
|
||||
|
||||
// ReadURL is a shortcut of ReadParams and ReadQuery.
|
||||
// It binds dynamic path parameters and URL query parameters
|
||||
// to the "ptr" pointer struct value.
|
||||
// The struct fields may contain "url" or "param" binding tags.
|
||||
// If a validator exists then it validates the result too.
|
||||
func (ctx *Context) ReadURL(ptr interface{}) error {
|
||||
values := make(map[string][]string, ctx.params.Len())
|
||||
ctx.params.Visit(func(key string, value string) {
|
||||
values[key] = strings.Split(value, "/")
|
||||
})
|
||||
|
||||
for k, v := range ctx.getQuery() {
|
||||
values[k] = append(values[k], v...)
|
||||
}
|
||||
|
||||
// Decode using all available binding tags (url, header, param).
|
||||
err := schema.Decode(values, ptr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.app.Validate(ptr)
|
||||
}
|
||||
|
||||
// ReadProtobuf binds the body to the "ptr" of a proto Message and returns any error.
|
||||
// Look `ReadJSONProtobuf` too.
|
||||
func (ctx *Context) ReadProtobuf(ptr proto.Message) error {
|
||||
|
|
Loading…
Reference in New Issue
Block a user