mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
38 lines
810 B
Go
38 lines
810 B
Go
|
// package main contains an example on how to use the ReadQuery,
|
||
|
// same way you can do the ReadJSON & ReadProtobuf and e.t.c.
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/kataras/iris/v12"
|
||
|
)
|
||
|
|
||
|
type myParams struct {
|
||
|
Name string `param:"name"`
|
||
|
Age int `param:"age"`
|
||
|
Tail []string `param:"tail"`
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
app := newApp()
|
||
|
|
||
|
// http://localhost:8080/kataras/27/iris/web/framework
|
||
|
// MyType: main.MyType{Name:"kataras", Age:27, Tail:[]string{"iris", "web", "framework"}}
|
||
|
app.Listen(":8080")
|
||
|
}
|
||
|
|
||
|
func newApp() *iris.Application {
|
||
|
app := iris.New()
|
||
|
|
||
|
app.Get("/{name}/{age:int}/{tail:path}", func(ctx iris.Context) {
|
||
|
var p myParams
|
||
|
if err := ctx.ReadParams(&p); err != nil {
|
||
|
ctx.StopWithError(iris.StatusInternalServerError, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
ctx.Writef("myParams: %#v", p)
|
||
|
})
|
||
|
|
||
|
return app
|
||
|
}
|