-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
43 lines (31 loc) · 857 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
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
"github.com/alexisvisco/kcd"
)
func main() {
r := chi.NewRouter()
r.Post("/", kcd.Handler(YourHttpHandler, http.StatusOK))
_ = http.ListenAndServe(":3000", r)
}
type NestedStruct struct {
Name string `query:"name"`
}
type CustomInput struct {
Nested NestedStruct `query:"nested"` // ?nested.name=kcd
NestedStruct // ?name=kcd
Anonymous struct {
Key string `query:"key"` // ?key=kcd
}
AnonymousValue struct {
Value string `query:"key"` // ?anonymous.key=kcd
NestedStruct // ?anonymous.name=kcd
} `query:"anonymous"`
}
func YourHttpHandler(in *CustomInput) (*CustomInput, error) {
fmt.Printf("%+v", in)
return in, nil
}
// Test it : curl -XPOST 'localhost:3000?nested.name=alexis&name=remi&key=antoine&anonymous.key=superman&anonymous.name=batman'