mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
2a4043a3c2
Former-commit-id: ccbe95de0badb1bf448fcc443cecda60772716dc
43 lines
804 B
Go
43 lines
804 B
Go
package main
|
|
|
|
import "github.com/kataras/iris/v12"
|
|
|
|
type (
|
|
testInput struct {
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
testOutput struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
)
|
|
|
|
func handler(id int, in testInput) testOutput {
|
|
return testOutput{
|
|
ID: id,
|
|
Name: in.Email,
|
|
}
|
|
}
|
|
|
|
func configureAPI(api *iris.APIContainer) {
|
|
/* Here is how you can inject a return value from a handler,
|
|
in this case the "testOutput":
|
|
api.UseResultHandler(func(next iris.ResultHandler) iris.ResultHandler {
|
|
return func(ctx iris.Context, v interface{}) error {
|
|
return next(ctx, map[string]interface{}{"injected": true})
|
|
}
|
|
})
|
|
*/
|
|
|
|
api.Post("/{id:int}", handler)
|
|
}
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
app.Logger().SetLevel("debug")
|
|
|
|
app.ConfigureContainer(configureAPI)
|
|
app.Listen(":8080")
|
|
}
|