Skip to content

Conversation

@prabirshrestha
Copy link

Initial PR for #3 which is similar to expressjs res.format(obj)

Usage:

app.Get("/", func (w http.ResponseWriter, r *http.Request) {
    response.Format(r, map[string]func() {
        "text/html": func () {
            w.Header().Set("Content-Type", "text/html")
            fmt.Fprintln(w, "Hello world<br/>")
            fmt.Fprint(w, r.Header.Get("Accept"))
        },
        "application/json": func () {
            response.JSON(w, map[string]string { "hello": "world" })
        },
        "default": func () {
            fmt.Fprintf(w, "default")
        },
    })
})

Currently I'm internally using bitbucket.org/ww/goautoneg which is a mercurial repository. We should have it hosted in github or embed it in response repository.

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