-
-
Notifications
You must be signed in to change notification settings - Fork 176
/
main.go
37 lines (29 loc) · 825 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// package main contains an example on how to use the ReadParams,
// same way you can do the ReadQuery, 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
// myParams: main.myParams{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
}