Skip to content

Commit

Permalink
Fixed labstack#310
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Rana <[email protected]>
  • Loading branch information
vishr committed Mar 6, 2016
1 parent 8916d55 commit a9c88ca
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 36 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import (

func main() {
e := echo.New()
e.Use(mw.Log())
e.Get("/", func(c echo.Context) error {
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Get("/", echo.HandlerFunc(func(c echo.Context) error {
return c.String(200, "Hello, World!")
})
e.Get("/v2", func(c echo.Context) error {
}))
e.Get("/v2", echo.HandlerFunc(func(c echo.Context) error {
return c.String(200, "Echo v2")
})
}))

// FastHTTP
// e.Run(fasthttp.New(":4444"))
// e.Run(fasthttp.New(":1323"))

// Standard
e.Run(standard.New(":4444"))
e.Run(standard.New(":1323"))
}
```

Expand Down Expand Up @@ -82,6 +83,10 @@ BenchmarkZeus_GithubAll 2000 748827 ns/op 30068
- Suggest new features/recipes
- Improve/fix documentation

## Support

- [Chat](https://gitter.im/labstack/echo)

## Credits
- [Vishal Rana](https://github.com/vishr) - Author
- [Nitin Rana](https://github.com/nr17) - Consultant
Expand Down
10 changes: 8 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type (
Path() string
P(int) string
Param(string) string
ParamNames() []string
Query(string) string
Form(string) string
Set(string, interface{})
Expand Down Expand Up @@ -148,6 +149,11 @@ func (c *context) Param(name string) (value string) {
return
}

// ParamNames returns path parameter names.
func (c *context) ParamNames() []string {
return c.pnames
}

// Query returns query parameter by name.
func (c *context) Query(name string) string {
return c.request.URL().QueryValue(name)
Expand All @@ -174,7 +180,7 @@ func (c *context) Set(key string, val interface{}) {
// Bind binds the request body into specified type `i`. The default binder does
// it based on Content-Type header.
func (c *context) Bind(i interface{}) error {
return c.echo.binder.Bind(c.request, i)
return c.echo.binder.Bind(i, c)
}

// Render renders a template with data and sends a text/html response with status
Expand All @@ -184,7 +190,7 @@ func (c *context) Render(code int, name string, data interface{}) (err error) {
return ErrRendererNotRegistered
}
buf := new(bytes.Buffer)
if err = c.echo.renderer.Render(buf, name, data); err != nil {
if err = c.echo.renderer.Render(buf, name, data, c); err != nil {
return
}
c.response.Header().Set(ContentType, TextHTMLCharsetUTF8)
Expand Down
6 changes: 5 additions & 1 deletion context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type (
}
)

func (t *Template) Render(w io.Writer, name string, data interface{}) error {
func (t *Template) Render(w io.Writer, name string, data interface{}, c Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}

Expand All @@ -46,6 +46,10 @@ func TestContext(t *testing.T) {
// Socket
assert.Nil(t, c.Socket())

// ParamNames
c.Object().pnames = []string{"uid", "fid"}
assert.EqualValues(t, []string{"uid", "fid"}, c.ParamNames())

// Param by id
c.Object().pnames = []string{"id"}
c.Object().pvalues = []string{"1"}
Expand Down
13 changes: 7 additions & 6 deletions echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type (

// Binder is the interface that wraps the Bind method.
Binder interface {
Bind(engine.Request, interface{}) error
Bind(interface{}, Context) error
}

binder struct {
Expand All @@ -76,7 +76,7 @@ type (

// Renderer is the interface that wraps the Render method.
Renderer interface {
Render(w io.Writer, name string, data interface{}) error
Render(io.Writer, string, interface{}, Context) error
}
)

Expand Down Expand Up @@ -444,15 +444,16 @@ func (e *HTTPError) Error() string {
return e.message
}

func (binder) Bind(r engine.Request, i interface{}) (err error) {
ct := r.Header().Get(ContentType)
func (binder) Bind(i interface{}, c Context) (err error) {
req := c.Request()
ct := req.Header().Get(ContentType)
err = ErrUnsupportedMediaType
if strings.HasPrefix(ct, ApplicationJSON) {
if err = json.NewDecoder(r.Body()).Decode(i); err != nil {
if err = json.NewDecoder(req.Body()).Decode(i); err != nil {
err = NewHTTPError(http.StatusBadRequest, err.Error())
}
} else if strings.HasPrefix(ct, ApplicationXML) {
if err = xml.NewDecoder(r.Body()).Decode(i); err != nil {
if err = xml.NewDecoder(req.Body()).Decode(i); err != nil {
err = NewHTTPError(http.StatusBadRequest, err.Error())
}
}
Expand Down
3 changes: 2 additions & 1 deletion website/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"baseurl": "http://labstack.com/echo",
"baseurl": "https://labstack.com/echo",
"languageCode": "en-us",
"title": "Echo",
"canonifyurls": true,
Expand All @@ -21,6 +21,7 @@
},

"params": {
"description": "Golang micro web framework, High performance, Minimalistic and Fast.",
"googleAnayticsId": "UA-51208124-3"
}
}
2 changes: 1 addition & 1 deletion website/content/guide/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Customization
menu:
side:
parent: guide
weight: 2
weight: 3
---

### HTTP error handler
Expand Down
2 changes: 1 addition & 1 deletion website/content/guide/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Error Handling
menu:
side:
parent: guide
weight: 7
weight: 8
---

Echo advocates centralized HTTP error handling by returning `error` from middleware
Expand Down
8 changes: 5 additions & 3 deletions website/content/guide/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ menu:
weight: 1
---

Echo has been developed and tested using Go `1.4.x`
Echo is developed and tested using Go `1.5.x` and `1.6.x`

Install the latest version of Echo via `go get`
#### Install the latest stable version of Echo via `go get`

```sh
$ go get github.com/labstack/echo
```

To upgrade
#### Update

```sh
$ go get -u github.com/labstack/echo
```

#### [Migrating from v1](/guide/migrating)

Echo follows [semantic versioning](http://semver.org) managed through GitHub releases.
Specific version of Echo can be installed using a [package manager](https://github.com/avelino/awesome-go#package-management).
2 changes: 1 addition & 1 deletion website/content/guide/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Middleware
menu:
side:
parent: guide
weight: 4
weight: 5
---

Middleware is a function which is chained in the HTTP request-response cycle. Middleware
Expand Down
2 changes: 1 addition & 1 deletion website/content/guide/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Request
menu:
side:
parent: guide
weight: 5
weight: 6
---

### Handler path
Expand Down
2 changes: 1 addition & 1 deletion website/content/guide/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Response
menu:
side:
parent: guide
weight: 6
weight: 7
---

### Template
Expand Down
2 changes: 1 addition & 1 deletion website/content/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Routing
menu:
side:
parent: guide
weight: 3
weight: 4
---

Echo's router is [fast, optimized]({{< relref "index.md#performance">}}) and
Expand Down
2 changes: 1 addition & 1 deletion website/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Index
---

# Echo
# ![Echo](/images/echo.svg) Echo

A fast and unfancy micro web framework for Go.

Expand Down
4 changes: 2 additions & 2 deletions website/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>
{{ if ne .URL "/" }}{{ .Title }} | {{ end }}{{ .Site.Title }}
{{ .Site.Title }} - {{ .Site.Params.description }}{{ if ne .URL "/" }} - {{ .Title }} {{ end }}
</title>
<meta name="description" content="">
<meta name="description" content="{{ .Site.Params.description }}">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- <link rel="apple-touch-icon" href="apple-touch-icon.png"> -->
Expand Down
6 changes: 3 additions & 3 deletions website/layouts/partials/header.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<a href="/" class="mdl-navigation__link mdl-layout-title">
{{ .Site.Title }}
<a href="https://labstack.com" class="mdl-navigation__link mdl-layout-title">
<img src="/images/logo.svg" alt="LabStack">
</a>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation mdl-layout--large-screen-only">
<a href="https://github.com/labstack/echo" class="mdl-navigation__link">
<i class="fa fa-github fa-lg"></i> GitHub
<i class="fa fa-github fa-2x"></i>
</a>
</nav>
</div>
Expand Down
8 changes: 4 additions & 4 deletions website/static/styles/echo.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
footer {
background-color: inherit !important;
border-top: 2px solid #E0E0E0;
border-top: 2px solid #e0e0e0;
}
.facebook a:hover {
color: #3B5998;
Expand All @@ -15,12 +15,12 @@ footer {
color: #333;
}
:not(pre) > code {
padding: 2px 4px;
background: #EEE;
padding: 0 4px;
background: #eee;
color: #424242;
font-size: .95em;
font-family: Source Code Pro, Monaco, Menlo, Consolas, monospace;
border: 1px solid #E0E0E0;
border: 1px solid #e0e0e0;
border-radius: 2px;
}
a:link {
Expand Down

0 comments on commit a9c88ca

Please sign in to comment.