File tree 5 files changed +91
-20
lines changed
5 files changed +91
-20
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,4 @@ exclude_paths:
9
9
- " examples/**"
10
10
- " .github/**"
11
11
- " testdata/**"
12
- - " **.md"
12
+ - " **.md"
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ "github.com/mojixcoder/kid"
7
+ )
8
+
9
+ type MeRequest struct {
10
+ LastName string `json:"last_name"`
11
+ }
12
+
13
+ type MeResponse struct {
14
+ FullName string `json:"full_name"`
15
+ Age int `json:"age"`
16
+ }
17
+
18
+ func main () {
19
+ k := kid .New ()
20
+
21
+ k .Get ("/me" , meHandler )
22
+
23
+ k .Run ()
24
+ }
25
+
26
+ func meHandler (c * kid.Context ) {
27
+ var req MeRequest
28
+
29
+ if err := c .ReadJSON (& req ); err != nil {
30
+ c .JSON (http .StatusBadRequest , kid.Map {"message" : "invalid request body" })
31
+ return
32
+ }
33
+
34
+ me := MeResponse {
35
+ FullName : "Mojix " + req .LastName ,
36
+ Age : 23 ,
37
+ }
38
+
39
+ c .JSON (http .StatusOK , me )
40
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "net/http"
6
+
7
+ "github.com/mojixcoder/kid"
8
+ )
9
+
10
+ func main () {
11
+ k := kid .New ()
12
+
13
+ k .Get ("/greet/{name}" , greetHandler )
14
+
15
+ // It will be matched to any number of paramters. Including zero and one and so on.
16
+ k .Get ("/path/{*starParam}" , starParamHandler )
17
+
18
+ k .Run ()
19
+ }
20
+
21
+ func greetHandler (c * kid.Context ) {
22
+ name := c .Param ("name" )
23
+
24
+ c .String (http .StatusOK , fmt .Sprintf ("Hello %s!" , name ))
25
+ }
26
+
27
+ func starParamHandler (c * kid.Context ) {
28
+ param := c .Param ("starParam" )
29
+
30
+ c .String (http .StatusOK , fmt .Sprintf ("Star path parameter: %q" , param ))
31
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "net/http"
5
+
6
+ "github.com/mojixcoder/kid"
7
+ )
8
+
9
+ func main () {
10
+ k := kid .New ()
11
+
12
+ k .Get ("/greet" , greetHandler )
13
+
14
+ k .Run ()
15
+ }
16
+
17
+ func greetHandler (c * kid.Context ) {
18
+ c .String (http .StatusOK , "Hello World!" )
19
+ }
You can’t perform that action at this time.
0 commit comments