mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
Separated Group from Echo to limit API
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
e0364caf36
commit
e119cbc2ea
24
echo.go
24
echo.go
@ -175,18 +175,6 @@ func New() (e *Echo) {
|
||||
return
|
||||
}
|
||||
|
||||
// Group creates a new sub router with prefix. It inherits all properties from
|
||||
// the parent. Passing middleware overrides parent middleware.
|
||||
func (e *Echo) Group(pfx string, m ...Middleware) *Echo {
|
||||
g := *e
|
||||
g.prefix = g.prefix + pfx
|
||||
if len(m) > 0 {
|
||||
g.middleware = nil
|
||||
g.Use(m...)
|
||||
}
|
||||
return &g
|
||||
}
|
||||
|
||||
// Router returns router.
|
||||
func (e *Echo) Router() *Router {
|
||||
return e.router
|
||||
@ -355,6 +343,18 @@ func (e *Echo) URL(h Handler, params ...interface{}) string {
|
||||
return e.URI(h, params...)
|
||||
}
|
||||
|
||||
// Group creates a new sub router with prefix. It inherits all properties from
|
||||
// the parent. Passing middleware overrides parent middleware.
|
||||
func (e *Echo) Group(prefix string, m ...Middleware) *Group {
|
||||
g := &Group{*e}
|
||||
g.echo.prefix += prefix
|
||||
if len(m) > 0 {
|
||||
g.echo.middleware = nil
|
||||
g.Use(m...)
|
||||
}
|
||||
return g
|
||||
}
|
||||
|
||||
func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c := e.pool.Get().(*Context)
|
||||
h, echo := e.router.Find(r.Method, r.URL.Path, c)
|
||||
|
52
group.go
52
group.go
@ -2,6 +2,56 @@ package echo
|
||||
|
||||
type (
|
||||
Group struct {
|
||||
*Echo
|
||||
echo Echo
|
||||
}
|
||||
)
|
||||
|
||||
func (g *Group) Use(m ...Middleware) {
|
||||
for _, h := range m {
|
||||
g.echo.middleware = append(g.echo.middleware, wrapMiddleware(h))
|
||||
}
|
||||
}
|
||||
|
||||
func (g *Group) Connect(path string, h Handler) {
|
||||
g.echo.Connect(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Delete(path string, h Handler) {
|
||||
g.echo.Delete(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Get(path string, h Handler) {
|
||||
g.echo.Get(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Head(path string, h Handler) {
|
||||
g.echo.Head(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Options(path string, h Handler) {
|
||||
g.echo.Options(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Patch(path string, h Handler) {
|
||||
g.echo.Patch(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Post(path string, h Handler) {
|
||||
g.echo.Post(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Put(path string, h Handler) {
|
||||
g.echo.Put(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Trace(path string, h Handler) {
|
||||
g.echo.Trace(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) WebSocket(path string, h HandlerFunc) {
|
||||
g.echo.WebSocket(path, h)
|
||||
}
|
||||
|
||||
func (g *Group) Group(prefix string, m ...Middleware) *Group {
|
||||
return g.echo.Group(prefix, m...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user