Skip to content

Adds Render(), JSON() and XML() facilities.#10

Open
manucorporat wants to merge 3 commits into
martini-contrib:masterfrom
manucorporat:master
Open

Adds Render(), JSON() and XML() facilities.#10
manucorporat wants to merge 3 commits into
martini-contrib:masterfrom
manucorporat:master

Conversation

@manucorporat

Copy link
Copy Markdown

Adds Encoder.Render() facility. Since encoder.Must is very frequently used:

enc.Render(result) == encoder.Must(enc.Encode(result))

and now you can use:

m.Use(encoder.JSON())

instead of:

m.Use(func(c martini.Context, w http.ResponseWriter) {
     c.MapTo(encoder.JsonEncoder{}, (*encoder.Encoder)(nil))
     w.Header().Set("Content-Type", "application/json; charset=utf-8")
})

Since encoder.Must is very frequently.
enc.Render(result)  ==  encoder.Must(enc.Encode(result))
Now, you can use:

```
m.Use(encoder.JSON())
```

instead of:

```
m.Use(func(c martini.Context, w http.ResponseWriter) {
    c.MapTo(encoder.JsonEncoder{}, (*encoder.Encoder)(nil))
    w.Header().Set("Content-Type", "application/json; charset=utf-8")
})
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant