mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Introduce go chi web framework as frontend of macaron, so that we can move routes from macaron to chi step by step (#7420)
* When route cannot be found on chi, go to macaron * Stick chi version to 1.5.0 * Follow router log setting
This commit is contained in:
		
							
								
								
									
										49
									
								
								vendor/github.com/go-chi/chi/chain.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								vendor/github.com/go-chi/chi/chain.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| package chi | ||||
|  | ||||
| import "net/http" | ||||
|  | ||||
| // Chain returns a Middlewares type from a slice of middleware handlers. | ||||
| func Chain(middlewares ...func(http.Handler) http.Handler) Middlewares { | ||||
| 	return Middlewares(middlewares) | ||||
| } | ||||
|  | ||||
| // Handler builds and returns a http.Handler from the chain of middlewares, | ||||
| // with `h http.Handler` as the final handler. | ||||
| func (mws Middlewares) Handler(h http.Handler) http.Handler { | ||||
| 	return &ChainHandler{mws, h, chain(mws, h)} | ||||
| } | ||||
|  | ||||
| // HandlerFunc builds and returns a http.Handler from the chain of middlewares, | ||||
| // with `h http.Handler` as the final handler. | ||||
| func (mws Middlewares) HandlerFunc(h http.HandlerFunc) http.Handler { | ||||
| 	return &ChainHandler{mws, h, chain(mws, h)} | ||||
| } | ||||
|  | ||||
| // ChainHandler is a http.Handler with support for handler composition and | ||||
| // execution. | ||||
| type ChainHandler struct { | ||||
| 	Middlewares Middlewares | ||||
| 	Endpoint    http.Handler | ||||
| 	chain       http.Handler | ||||
| } | ||||
|  | ||||
| func (c *ChainHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||||
| 	c.chain.ServeHTTP(w, r) | ||||
| } | ||||
|  | ||||
| // chain builds a http.Handler composed of an inline middleware stack and endpoint | ||||
| // handler in the order they are passed. | ||||
| func chain(middlewares []func(http.Handler) http.Handler, endpoint http.Handler) http.Handler { | ||||
| 	// Return ahead of time if there aren't any middlewares for the chain | ||||
| 	if len(middlewares) == 0 { | ||||
| 		return endpoint | ||||
| 	} | ||||
|  | ||||
| 	// Wrap the end handler with the middleware chain | ||||
| 	h := middlewares[len(middlewares)-1](endpoint) | ||||
| 	for i := len(middlewares) - 2; i >= 0; i-- { | ||||
| 		h = middlewares[i](h) | ||||
| 	} | ||||
|  | ||||
| 	return h | ||||
| } | ||||
		Reference in New Issue
	
	Block a user