2020-03-01 01:17:19 +01:00
|
|
|
package main
|
|
|
|
|
2020-05-07 00:14:41 +02:00
|
|
|
import (
|
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
)
|
2020-03-01 01:17:19 +01:00
|
|
|
|
|
|
|
type (
|
|
|
|
testInput struct {
|
2020-05-07 00:14:41 +02:00
|
|
|
Email string `json:"email" validate:"required"`
|
2020-03-01 01:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
testOutput struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func handler(id int, in testInput) testOutput {
|
|
|
|
return testOutput{
|
|
|
|
ID: id,
|
|
|
|
Name: in.Email,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-18 21:40:47 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-03-01 01:17:19 +01:00
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-05-07 00:14:41 +02:00
|
|
|
app.Validator = validator.New()
|
2020-04-28 21:34:36 +02:00
|
|
|
app.Logger().SetLevel("debug")
|
|
|
|
|
2020-04-18 21:40:47 +02:00
|
|
|
app.ConfigureContainer(configureAPI)
|
2020-03-02 09:07:44 +01:00
|
|
|
app.Listen(":8080")
|
2020-03-01 01:17:19 +01:00
|
|
|
}
|