mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
reorganization of _examples and add some new examples such as iris+groupcache+mysql+docker
Former-commit-id: ed635ee95de7160cde11eaabc0c1dcb0e460a620
This commit is contained in:
29
_examples/request-body/read-query/main.go
Normal file
29
_examples/request-body/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/v12"
|
||||
)
|
||||
|
||||
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.StopWithError(iris.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Writef("MyType: %#v", t)
|
||||
})
|
||||
|
||||
// http://localhost:8080?name=iris&age=3
|
||||
app.Listen(":8080")
|
||||
}
|
||||
Reference in New Issue
Block a user