Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added response.Format(request, handlers) for content negotiation #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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