iris/_examples/dependency-injection/basic/main.go
Gerasimos (Makis) Maropoulos dcf02480b3 Implement ResultHandler as requested at: https://github.com/kataras/iris/issues/1465
Former-commit-id: 9d76c2f00766afd53cf6e591c25f861f179dd817
2020-04-18 22:40:47 +03:00

41 lines
771 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.ConfigureContainer(configureAPI)
app.Listen(":8080")
}