2020-07-26 19:28:31 +02:00
|
|
|
// package main contains an example on how to use the ReadQuery,
|
|
|
|
// same way you can do the ReadJSON & ReadProtobuf and e.t.c.
|
2019-07-24 02:29:42 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2019-07-24 02:29:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type MyType struct {
|
2020-08-31 19:30:01 +02:00
|
|
|
Name string `url:"name,required"`
|
2019-07-24 02:29:42 +02:00
|
|
|
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) {
|
2020-05-17 23:25:38 +02:00
|
|
|
ctx.StopWithError(iris.StatusInternalServerError, err)
|
|
|
|
return
|
2019-07-24 02:29:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Writef("MyType: %#v", t)
|
|
|
|
})
|
|
|
|
|
2020-08-31 04:07:55 +02:00
|
|
|
app.Get("/simple", func(ctx iris.Context) {
|
|
|
|
names := ctx.URLParamSlice("name")
|
2020-08-31 08:48:37 +02:00
|
|
|
ctx.Writef("names: %v", names)
|
2020-08-31 04:07:55 +02:00
|
|
|
})
|
|
|
|
|
2019-07-24 02:29:42 +02:00
|
|
|
// http://localhost:8080?name=iris&age=3
|
2020-08-31 04:07:55 +02:00
|
|
|
// http://localhost:8080/simple?name=john&name=doe&name=kataras
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2019-07-24 02:29:42 +02:00
|
|
|
}
|