update: route handlers execute rule(execute all -> manual next)
This commit is contained in:
		
							
								
								
									
										12
									
								
								ctx.go
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								ctx.go
									
									
									
									
									
								
							| @@ -81,14 +81,14 @@ func (c *Ctx) Cookies(key string, defaultValue ...string) string { | |||||||
|  |  | ||||||
| func (c *Ctx) Next() error { | func (c *Ctx) Next() error { | ||||||
| 	c.index++ | 	c.index++ | ||||||
| 	s := len(c.handlers) |  | ||||||
| 	for ; c.index < s; c.index++ { | 	var err error | ||||||
| 		if err := c.handlers[c.index](c); err != nil { |  | ||||||
| 			return err | 	if c.index < len(c.handlers) { | ||||||
| 		} | 		err = c.handlers[c.index](c) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
| /* =============================================================== | /* =============================================================== | ||||||
|   | |||||||
							
								
								
									
										27
									
								
								xtest/multihandler/main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								xtest/multihandler/main.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | |||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"github.com/loveuer/nf" | ||||||
|  | 	"log" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func main() { | ||||||
|  | 	app := nf.New() | ||||||
|  |  | ||||||
|  | 	app.Get("/nice", h1, h2) | ||||||
|  |  | ||||||
|  | 	log.Fatal(app.Run(":3333")) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func h1(c *nf.Ctx) error { | ||||||
|  | 	you := c.Query("to") | ||||||
|  | 	if you == "you" { | ||||||
|  | 		return c.JSON(nf.Map{"status": 201, "msg": "nice to meet you"}) | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return c.Next() | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func h2(c *nf.Ctx) error { | ||||||
|  | 	return c.JSON(nf.Map{"status": 200, "msg": "hello world"}) | ||||||
|  | } | ||||||
							
								
								
									
										5
									
								
								xtest/multihandler/req.http
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								xtest/multihandler/req.http
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | ### test multi handlers no next | ||||||
|  | GET http://127.0.0.1:3333/nice?to=you | ||||||
|  |  | ||||||
|  | ### test multi handlers do next | ||||||
|  | GET http://127.0.0.1:3333/nice?to=nf | ||||||
		Reference in New Issue
	
	Block a user