mirror of
				https://github.com/labstack/echo.git
				synced 2025-10-30 23:57:38 +02:00 
			
		
		
		
	
							
								
								
									
										74
									
								
								bolt.go
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								bolt.go
									
									
									
									
									
								
							| @@ -65,12 +65,12 @@ func New() (b *Bolt) { | |||||||
| func (h HandlerFunc) ServeHTTP(r http.ResponseWriter, w *http.Request) { | func (h HandlerFunc) ServeHTTP(r http.ResponseWriter, w *http.Request) { | ||||||
| } | } | ||||||
|  |  | ||||||
| func (b *Bolt) Sub(prefix string, m ...MiddlewareFunc) *Bolt { | // func (b *Bolt) Sub(prefix string, m ...MiddlewareFunc) *Bolt { | ||||||
| 	return &Bolt{ | // 	return &Bolt{ | ||||||
| 	// prefix:   b.prefix + prefix, | // prefix:   b.prefix + prefix, | ||||||
| 	// middleware: append(b.handlers, handlers...), | // middleware: append(b.handlers, handlers...), | ||||||
| 	} | // 	} | ||||||
| } | // } | ||||||
|  |  | ||||||
| // MaxParam sets the max path params allowed. Default is 5, good enough for | // MaxParam sets the max path params allowed. Default is 5, good enough for | ||||||
| // many users. | // many users. | ||||||
| @@ -79,18 +79,18 @@ func (b *Bolt) MaxParam(n uint8) { | |||||||
| } | } | ||||||
|  |  | ||||||
| // NotFoundHandler sets a custom NotFound handler. | // NotFoundHandler sets a custom NotFound handler. | ||||||
| func (b *Bolt) NotFoundHandler(h HandlerFunc) { | func (b *Bolt) NotFoundHandler(h Handler) { | ||||||
| 	b.notFoundHandler = h | 	b.notFoundHandler = wrapH(h) | ||||||
| } | } | ||||||
|  |  | ||||||
| // MethodNotAllowedHandler sets a custom MethodNotAllowed handler. | // MethodNotAllowedHandler sets a custom MethodNotAllowed handler. | ||||||
| func (b *Bolt) MethodNotAllowedHandler(h HandlerFunc) { | func (b *Bolt) MethodNotAllowedHandler(h Handler) { | ||||||
| 	b.methodNotAllowedHandler = h | 	b.methodNotAllowedHandler = wrapH(h) | ||||||
| } | } | ||||||
|  |  | ||||||
| // InternalServerErrorHandler sets a custom InternalServerError handler. | // InternalServerErrorHandler sets a custom InternalServerError handler. | ||||||
| func (b *Bolt) InternalServerErrorHandler(h HandlerFunc) { | func (b *Bolt) InternalServerErrorHandler(h Handler) { | ||||||
| 	b.internalServerErrorHandler = h | 	b.internalServerErrorHandler = wrapH(h) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Use adds handler to the middleware chain. | // Use adds handler to the middleware chain. | ||||||
| @@ -100,61 +100,49 @@ func (b *Bolt) Use(m ...Middleware) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // Connect adds a CONNECT route. | // Connect adds a CONNECT route > handler to the router. | ||||||
| func (b *Bolt) Connect(path string, h Handler) { | func (b *Bolt) Connect(path string, h Handler) { | ||||||
| 	b.Handle("CONNECT", path, h) | 	b.Router.Add("CONNECT", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Delete adds a DELETE route. | // Delete adds a DELETE route > handler to the router. | ||||||
| func (b *Bolt) Delete(path string, h Handler) { | func (b *Bolt) Delete(path string, h Handler) { | ||||||
| 	b.Handle("DELETE", path, h) | 	b.Router.Add("DELETE", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Get adds a GET route. | // Get adds a GET route > handler to the router. | ||||||
| func (b *Bolt) Get(path string, h Handler) { | func (b *Bolt) Get(path string, h Handler) { | ||||||
| 	b.Handle("GET", path, h) | 	b.Router.Add("GET", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Head adds a HEAD route. | // Head adds a HEAD route > handler to the router. | ||||||
| func (b *Bolt) Head(path string, h Handler) { | func (b *Bolt) Head(path string, h Handler) { | ||||||
| 	b.Handle("HEAD", path, h) | 	b.Router.Add("HEAD", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Options adds an OPTIONS route. | // Options adds an OPTIONS route > handler to the router. | ||||||
| func (b *Bolt) Options(path string, h Handler) { | func (b *Bolt) Options(path string, h Handler) { | ||||||
| 	b.Handle("OPTIONS", path, h) | 	b.Router.Add("OPTIONS", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Patch adds a PATCH route. | // Patch adds a PATCH route > handler to the router. | ||||||
| func (b *Bolt) Patch(path string, h Handler) { | func (b *Bolt) Patch(path string, h Handler) { | ||||||
| 	b.Handle("PATCH", path, h) | 	b.Router.Add("PATCH", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Post adds a POST route. | // Post adds a POST route > handler to the router. | ||||||
| func (b *Bolt) Post(path string, h Handler) { | func (b *Bolt) Post(path string, h Handler) { | ||||||
| 	b.Handle("POST", path, h) | 	b.Router.Add("POST", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Put adds a PUT route. | // Put adds a PUT route > handler to the router. | ||||||
| func (b *Bolt) Put(path string, h Handler) { | func (b *Bolt) Put(path string, h Handler) { | ||||||
| 	b.Handle("PUT", path, h) | 	b.Router.Add("PUT", path, wrapH(h)) | ||||||
| } | } | ||||||
|  |  | ||||||
| // Trace adds a TRACE route. | // Trace adds a TRACE route > handler to the router. | ||||||
| func (b *Bolt) Trace(path string, h Handler) { | func (b *Bolt) Trace(path string, h Handler) { | ||||||
| 	b.Handle("TRACE", path, h) | 	b.Router.Add("TRACE", path, wrapH(h)) | ||||||
| } |  | ||||||
|  |  | ||||||
| // Handle adds method, path  handler to the router. |  | ||||||
| func (b *Bolt) Handle(method, path string, h Handler) { |  | ||||||
| 	b.Router.Add(method, path, b.wrapH(h)) |  | ||||||
| 	// hs := append(b.middleware, wrap(h, false)) |  | ||||||
| 	// l := len(hs) |  | ||||||
| 	// b.Router.Add(method, path, func(c *Context) { |  | ||||||
| 	// 	c.handlers = hs |  | ||||||
| 	// 	c.l = l |  | ||||||
| 	// c.Next() |  | ||||||
| 	// }) |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Static serves static files. | // Static serves static files. | ||||||
| @@ -226,7 +214,7 @@ func wrapM(m Middleware) MiddlewareFunc { | |||||||
| } | } | ||||||
|  |  | ||||||
| // wraps Handler | // wraps Handler | ||||||
| func (b *Bolt) wrapH(h Handler) HandlerFunc { | func wrapH(h Handler) HandlerFunc { | ||||||
| 	switch h := h.(type) { | 	switch h := h.(type) { | ||||||
| 	case func(*Context): | 	case func(*Context): | ||||||
| 		return HandlerFunc(h) | 		return HandlerFunc(h) | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								context.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								context.go
									
									
									
									
									
								
							| @@ -14,10 +14,7 @@ type ( | |||||||
| 		Request  *http.Request | 		Request  *http.Request | ||||||
| 		Response *response | 		Response *response | ||||||
| 		params   Params | 		params   Params | ||||||
| 		handlers []HandlerFunc |  | ||||||
| 		store    map[string]interface{} | 		store    map[string]interface{} | ||||||
| 		// l        int // Handlers' length |  | ||||||
| 		// i        int // Current handler index |  | ||||||
| 		bolt     *Bolt | 		bolt     *Bolt | ||||||
| 	} | 	} | ||||||
| 	store map[string]interface{} | 	store map[string]interface{} | ||||||
| @@ -63,14 +60,6 @@ func (c *Context) JSON(n int, i interface{}) { | |||||||
| // func (c *Context) File(n int, file, name string) { | // func (c *Context) File(n int, file, name string) { | ||||||
| // } | // } | ||||||
|  |  | ||||||
| // Next executes the next handler in the chain. |  | ||||||
| // func (c *Context) Next() { |  | ||||||
| // 	c.i++ |  | ||||||
| // 	if c.i < c.l { |  | ||||||
| // 		c.handlers[c.i](c) |  | ||||||
| // 	} |  | ||||||
| // } |  | ||||||
|  |  | ||||||
| // Get retrieves data from the context. | // Get retrieves data from the context. | ||||||
| func (c *Context) Get(key string) interface{} { | func (c *Context) Get(key string) interface{} { | ||||||
| 	return c.store[key] | 	return c.store[key] | ||||||
| @@ -89,10 +78,4 @@ func (c *Context) Redirect(n int, url string) { | |||||||
| func (c *Context) reset(rw http.ResponseWriter, r *http.Request) { | func (c *Context) reset(rw http.ResponseWriter, r *http.Request) { | ||||||
| 	c.Response.reset(rw) | 	c.Response.reset(rw) | ||||||
| 	c.Request = r | 	c.Request = r | ||||||
| 	// c.i = -1 |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // Halt halts the current request. |  | ||||||
| // func (c *Context) Halt() { |  | ||||||
| // 	c.i = c.l |  | ||||||
| // } |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user