Skip to content

Commit

Permalink
Separated Group from Echo to limit API
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <vr@labstack.com>
  • Loading branch information
vishr committed May 23, 2015
1 parent e0364ca commit e119cbc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
24 changes: 12 additions & 12 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
52 changes: 51 additions & 1 deletion group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}

0 comments on commit e119cbc

Please sign in to comment.