mirror of
https://github.com/kataras/iris.git
synced 2025-02-09 02:34:55 +01:00
39 lines
602 B
Go
39 lines
602 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/kataras/iris/v12"
|
||
|
"github.com/kataras/iris/v12/hero"
|
||
|
)
|
||
|
|
||
|
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 dependency(ctx iris.Context) (in testInput, err error) {
|
||
|
err = ctx.ReadJSON(&in)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
app := iris.New()
|
||
|
|
||
|
c := hero.New()
|
||
|
c.Register(dependency)
|
||
|
app.Post("/{id:int}", c.Handler(handler))
|
||
|
app.Listen(":5000", iris.WithOptimizations)
|
||
|
}
|