IrisHandler tests iris handler
()
| 12 | |
| 13 | // IrisHandler tests iris handler |
| 14 | func IrisHandler() http.Handler { |
| 15 | app := iris.New() |
| 16 | |
| 17 | sess := sessions.New(sessions.Config{ |
| 18 | Cookie: "irissessionid", |
| 19 | }) |
| 20 | |
| 21 | app.Get("/things", func(ctx iris.Context) { |
| 22 | ctx.JSON([]interface{}{ |
| 23 | iris.Map{ |
| 24 | "name": "foo", |
| 25 | "description": "foo thing", |
| 26 | }, |
| 27 | iris.Map{ |
| 28 | "name": "bar", |
| 29 | "description": "bar thing", |
| 30 | }, |
| 31 | }) |
| 32 | }) |
| 33 | |
| 34 | app.Post("/redirect", func(ctx iris.Context) { |
| 35 | ctx.Redirect("/things", iris.StatusFound) |
| 36 | }) |
| 37 | |
| 38 | app.Post("/params/{x}/{y}", func(ctx iris.Context) { |
| 39 | ctx.JSON(iris.Map{ |
| 40 | "x": ctx.Params().Get("x"), |
| 41 | "y": ctx.Params().Get("y"), |
| 42 | "q": ctx.URLParam("q"), |
| 43 | "p1": ctx.FormValue("p1"), |
| 44 | "p2": ctx.FormValue("p2"), |
| 45 | }) |
| 46 | }) |
| 47 | |
| 48 | auth := basicauth.Default(map[string]string{ |
| 49 | "ford": "betelgeuse7", |
| 50 | }) |
| 51 | |
| 52 | app.Get("/auth", auth, func(ctx iris.Context) { |
| 53 | ctx.Writef("authenticated!") |
| 54 | }) |
| 55 | |
| 56 | app.Post("/session/set", func(ctx iris.Context) { |
| 57 | session := sess.Start(ctx) |
| 58 | |
| 59 | v := iris.Map{} |
| 60 | |
| 61 | if err := ctx.ReadJSON(&v); err != nil { |
| 62 | ctx.StatusCode(iris.StatusBadRequest) |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | session.Set("name", v["name"]) |
| 67 | }) |
| 68 | |
| 69 | app.Get("/session/get", func(ctx iris.Context) { |
| 70 | session := sess.Start(ctx) |
| 71 |
searching dependent graphs…