-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
main.go
47 lines (38 loc) · 905 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
38
39
40
41
42
43
44
45
46
47
package main
import (
"github.com/kataras/iris/v12"
"github.com/go-playground/validator/v10"
)
type (
testInput struct {
Email string `json:"email" validate:"required"`
}
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.Validator = validator.New()
app.Logger().SetLevel("debug")
app.ConfigureContainer(configureAPI)
app.Listen(":8080")
}