Skip to content

Commit

Permalink
Fixed labstack#463
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Apr 11, 2016
1 parent f8117ac commit 609587e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ Middleware | Description

##### [More...](https://labstack.com/echo/guide/middleware/)

#### Third-party Middleware

Middleware | Description
:--- | :---
[echoperm](https://github.com/xyproto/echoperm) | Keeping track of users, login states and permissions.

### Next

- Head over to [guide](https://labstack.com/echo/guide/installation/)
Expand Down
7 changes: 7 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ type (
// Error invokes the registered HTTP error handler. Generally used by middleware.
Error(err error)

// Handler returns the matched handler by router.
Handler() HandlerFunc

// Logger returns the `Logger` instance.
Logger() *log.Logger

Expand Down Expand Up @@ -408,6 +411,10 @@ func (c *context) Echo() *Echo {
return c.echo
}

func (c *context) Handler() HandlerFunc {
return c.handler
}

func (c *context) Logger() *log.Logger {
return c.echo.logger
}
Expand Down
16 changes: 16 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package echo

import (
"bytes"
"errors"
"io"
"net/http"
Expand Down Expand Up @@ -266,6 +267,21 @@ func TestContextServeContent(t *testing.T) {
}
}

func TestContextHandler(t *testing.T) {
e := New()
r := e.Router()
b := new(bytes.Buffer)

r.Add(GET, "/handler", func(Context) error {
_, err := b.Write([]byte("handler"))
return err
}, e)
c := NewContext(nil, nil, e)
r.Find(GET, "/handler", c)
c.Handler()(c)
assert.Equal(t, "handler", b.String())
}

func testBindOk(t *testing.T, c Context, ct string) {
c.Request().Header().Set(HeaderContentType, ct)
u := new(user)
Expand Down

0 comments on commit 609587e

Please sign in to comment.