alpha: v0.0.1
This commit is contained in:
		
							
								
								
									
										2
									
								
								xtest/basic/basic.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								xtest/basic/basic.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| ### basic - get | ||||
| GET http://127.0.0.1/hello/nf | ||||
							
								
								
									
										17
									
								
								xtest/basic/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								xtest/basic/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"github.com/loveuer/nf" | ||||
| 	"log" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	app := nf.New() | ||||
|  | ||||
| 	app.Get("/hello/:name", func(c *nf.Ctx) error { | ||||
| 		name := c.Param("name") | ||||
| 		return c.JSON(nf.Map{"status": 200, "data": "hello, " + name}) | ||||
| 	}) | ||||
|  | ||||
| 	log.Fatal(app.Run("0.0.0.0:80")) | ||||
| } | ||||
							
								
								
									
										9
									
								
								xtest/bodyLimit/body_limit.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								xtest/bodyLimit/body_limit.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| ### body_limit | ||||
| POST http://127.0.0.1/data | ||||
| Content-Type: application/json | ||||
|  | ||||
| { | ||||
|   "name": "zyp", | ||||
|   "age": 19, | ||||
|   "likes": ["2233"] | ||||
| } | ||||
							
								
								
									
										50
									
								
								xtest/bodyLimit/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								xtest/bodyLimit/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"github.com/loveuer/nf" | ||||
| 	"log" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	app := nf.New(nf.Config{BodyLimit: -1}) | ||||
|  | ||||
| 	app.Post("/data", func(c *nf.Ctx) error { | ||||
| 		type Req struct { | ||||
| 			Name  string   `json:"name"` | ||||
| 			Age   int      `json:"age"` | ||||
| 			Likes []string `json:"likes"` | ||||
| 		} | ||||
|  | ||||
| 		var ( | ||||
| 			err error | ||||
| 			req = new(Req) | ||||
| 		) | ||||
|  | ||||
| 		if err = c.BodyParser(req); err != nil { | ||||
| 			return c.JSON(nf.Map{"status": 400, "err": err.Error()}) | ||||
| 		} | ||||
|  | ||||
| 		return c.JSON(nf.Map{"status": 200, "data": req}) | ||||
| 	}) | ||||
|  | ||||
| 	app.Post("/url", func(c *nf.Ctx) error { | ||||
| 		type Req struct { | ||||
| 			Name  string   `form:"name"` | ||||
| 			Age   int      `form:"age"` | ||||
| 			Likes []string `form:"likes"` | ||||
| 		} | ||||
|  | ||||
| 		var ( | ||||
| 			err error | ||||
| 			req = new(Req) | ||||
| 		) | ||||
|  | ||||
| 		if err = c.BodyParser(req); err != nil { | ||||
| 			return c.JSON(nf.Map{"status": 400, "err": err.Error()}) | ||||
| 		} | ||||
|  | ||||
| 		return c.JSON(nf.Map{"status": 200, "data": req}) | ||||
| 	}) | ||||
|  | ||||
| 	log.Fatal(app.Run("0.0.0.0:80")) | ||||
| } | ||||
							
								
								
									
										24
									
								
								xtest/panic/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								xtest/panic/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"github.com/loveuer/nf" | ||||
| 	"log" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	app := nf.New(nf.Config{ | ||||
| 		DisableRecover: true, | ||||
| 	}) | ||||
|  | ||||
| 	app.Get("/hello/:name", func(c *nf.Ctx) error { | ||||
| 		name := c.Param("name") | ||||
|  | ||||
| 		if name == "nf" { | ||||
| 			panic("name is nf") | ||||
| 		} | ||||
|  | ||||
| 		return c.JSON("nice") | ||||
| 	}) | ||||
|  | ||||
| 	log.Fatal(app.Run("0.0.0.0:80")) | ||||
| } | ||||
							
								
								
									
										5
									
								
								xtest/panic/panic.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								xtest/panic/panic.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| ### panic test | ||||
| GET http://127.0.0.1/hello/nf | ||||
|  | ||||
| ### if covered? | ||||
| GET http://127.0.0.1/hello/world | ||||
							
								
								
									
										31
									
								
								xtest/queryParser/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								xtest/queryParser/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| package main | ||||
|  | ||||
| import ( | ||||
| 	"github.com/loveuer/nf" | ||||
| 	"log" | ||||
| ) | ||||
|  | ||||
| func main() { | ||||
| 	app := nf.New() | ||||
|  | ||||
| 	app.Get("/hello", func(c *nf.Ctx) error { | ||||
| 		type Req struct { | ||||
| 			Name  string   `query:"name"` | ||||
| 			Age   int      `query:"age"` | ||||
| 			Likes []string `query:"likes"` | ||||
| 		} | ||||
|  | ||||
| 		var ( | ||||
| 			err error | ||||
| 			req = new(Req) | ||||
| 		) | ||||
|  | ||||
| 		if err = c.QueryParser(req); err != nil { | ||||
| 			return nf.NewNFError(400, err.Error()) | ||||
| 		} | ||||
|  | ||||
| 		return c.JSON(nf.Map{"status": 200, "data": req}) | ||||
| 	}) | ||||
|  | ||||
| 	log.Fatal(app.Run("0.0.0.0:80")) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user