mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
implement ReadQuery with 'url' struct field tag name strictly, as requested at: #1207
Former-commit-id: dc0c237f62aa6db5a0c1755b2074d8a18dba0d8f
This commit is contained in:
29
_examples/http_request/read-query/main.go
Normal file
29
_examples/http_request/read-query/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
type MyType struct {
|
||||
Name string `url:"name"`
|
||||
Age int `url:"age"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
var t MyType
|
||||
err := ctx.ReadQuery(&t)
|
||||
if err != nil && !iris.IsErrPath(err) {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
ctx.WriteString(err.Error())
|
||||
}
|
||||
|
||||
ctx.Writef("MyType: %#v", t)
|
||||
})
|
||||
|
||||
// http://localhost:8080?name=iris&age=3
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
Reference in New Issue
Block a user