x: github.com/gobuffalo/x/responder Index | Files

package responder

import "github.com/gobuffalo/x/responder"

Index

Package Files

responder.go

type Responder Uses

type Responder struct {
    // contains filtered or unexported fields
}

Responder holds the mappings of content-type to handler

func Wants Uses

func Wants(ct string, h buffalo.Handler) Responder

Wants maps a content-type, or part of one ("json", "html", "form", etc...), to a buffalo.Handler to respond with when it gets that content-type, returns a Responder that can be used for further mappings.

func (Responder) Respond Uses

func (r Responder) Respond(ctx buffalo.Context) error

Respond with a mapped buffalo.Handler, if one exists, returns an error if one does not.

func UserList(c buffalo.Context) error {

// do some work
return responder.Wants("html", func (c buffalo.Context) error {
	return c.Render(200, r.HTML("some/template.html")
}).Wants("json", func (c buffalo.Context) error {
	return c.Render(200, r.JSON(user))
}).Respond(c)

}

func (Responder) Wants Uses

func (r Responder) Wants(ct string, h buffalo.Handler) Responder

Wants maps a content-type, or part of one ("json", "html", "form", etc...), to a buffalo.Handler to respond with when it gets that content-type.

Package responder imports 4 packages (graph) and is imported by 1 packages. Updated 2019-07-21. Refresh now. Tools for package owners.