mirror of
https://github.com/kataras/iris.git
synced 2025-12-27 23:07:03 +00:00
implement ReadQuery with 'url' struct field tag name strictly, as requested at: #1207
Former-commit-id: dc0c237f62aa6db5a0c1755b2074d8a18dba0d8f
This commit is contained in:
@@ -225,6 +225,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
|
||||
* [Struct Validation](http_request/read-json-struct-validation/main.go)
|
||||
- [Read XML](http_request/read-xml/main.go)
|
||||
- [Read Form](http_request/read-form/main.go)
|
||||
- [Read Query](http_request/read-query/main.go) **NEW**
|
||||
- [Read Custom per type](http_request/read-custom-per-type/main.go)
|
||||
- [Read Custom via Unmarshaler](http_request/read-custom-via-unmarshaler/main.go)
|
||||
- [Read Many times](http_request/read-many/main.go)
|
||||
|
||||
@@ -331,6 +331,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
|
||||
- [读取JSON](http_request/read-json/main.go)
|
||||
- [读取XML](http_request/read-xml/main.go)
|
||||
- [读取Form](http_request/read-form/main.go)
|
||||
- [读取Query](http_request/read-query/main.go) **更新**
|
||||
- [读取每个类型的自定义结果Custom per type](http_request/read-custom-per-type/main.go)
|
||||
- [通过Unmarshaler读取Custom](http_request/read-custom-via-unmarshaler/main.go)
|
||||
- [上传/读取文件Upload/Read File](http_request/upload-file/main.go)
|
||||
|
||||
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