update: hide Param, add SetParam(can't cover value)
This commit is contained in:
		
							
								
								
									
										3
									
								
								app.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								app.go
									
									
									
									
									
								
							| @@ -165,8 +165,9 @@ func (a *App) handleHTTPRequest(c *Ctx) { | ||||
| 		// Find route in tree | ||||
| 		value := root.getValue(rPath, c.params, c.skippedNodes, unescape) | ||||
| 		if value.params != nil { | ||||
| 			c.Params = *value.params | ||||
| 			c.params = value.params | ||||
| 		} | ||||
|  | ||||
| 		if value.handlers != nil { | ||||
| 			c.handlers = value.handlers | ||||
| 			c.fullPath = value.fullPath | ||||
|   | ||||
							
								
								
									
										9
									
								
								ctx.go
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								ctx.go
									
									
									
									
									
								
							| @@ -29,7 +29,7 @@ type Ctx struct { | ||||
| 	locals       map[string]interface{} | ||||
| 	skippedNodes *[]skippedNode | ||||
| 	fullPath     string | ||||
| 	Params       Params | ||||
| 	//Params       Params | ||||
| } | ||||
|  | ||||
| func newContext(app *App, writer http.ResponseWriter, request *http.Request) *Ctx { | ||||
| @@ -144,7 +144,12 @@ func (c *Ctx) verify() error { | ||||
| } | ||||
|  | ||||
| func (c *Ctx) Param(key string) string { | ||||
| 	return c.Params.ByName(key) | ||||
| 	return c.params.ByName(key) | ||||
| } | ||||
|  | ||||
| func (c *Ctx) SetParam(key, value string) { | ||||
| 	params := append(*c.params, Param{Key: key, Value: value}) | ||||
| 	c.params = ¶ms | ||||
| } | ||||
|  | ||||
| func (c *Ctx) Form(key string) string { | ||||
|   | ||||
| @@ -13,8 +13,15 @@ func main() { | ||||
| 	}) | ||||
|  | ||||
| 	api := app.Group("/api") | ||||
| 	api.Get("/1", func(c *nf.Ctx) error { | ||||
| 		return c.SendString("nice") | ||||
| 	api.Use(func(c *nf.Ctx) error { | ||||
| 		c.SetParam("age", "18") | ||||
| 		return c.Next() | ||||
| 	}) | ||||
|  | ||||
| 	api.Get("/:name", func(c *nf.Ctx) error { | ||||
| 		name := c.Param("name") | ||||
| 		age := c.Param("age") | ||||
| 		return c.SendString(name + "@" + age) | ||||
| 	}) | ||||
|  | ||||
| 	log.Fatal(app.Run(":80")) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user