Documentation ¶
Index ¶
- Variables
- func ActorID(actor Actor) string
- func ContextParams(context *ctx.Context) httprouter.Params
- func MustSchema(schemaString string) *schema.Schema
- func MustSchemaFromFile(file string) *schema.Schema
- func RegisterCriteriaTransformer(transformer func(*ctx.Context, *Criteria))
- func RespondWithData(w http.ResponseWriter, r *http.Request, data interface{}, code int)
- func RespondWithError(w http.ResponseWriter, r *http.Request, err error)
- func RespondWithRenderedData(renderer Renderer, w http.ResponseWriter, r *http.Request, data interface{}, ...)
- func RespondWithStatusCode(w http.ResponseWriter, r *http.Request, code int)
- func SetContextCriteria(context *ctx.Context, criteria *Criteria)
- func SetContextParams(context *ctx.Context, params httprouter.Params)
- func UnmarshalAndValidateRequestSchema(context *ctx.Context, s *schema.Schema, obj interface{}) error
- func UnmarshalAndValidateSchema(body []byte, s *schema.Schema, obj interface{}) error
- type APIError
- type ActionHandler
- type ActionHandlerFunc
- type ActionProcessor
- type Actor
- type AnnotatedError
- type Criteria
- type DescriptiveError
- type Renderer
- type Response
- type StatusError
- type StructuredLogsError
Constants ¶
This section is empty.
Variables ¶
var EmptyResponse = &Response{}
EmptyResponse is used to determine if a response should be empty.
var SideloadQueryKey = "include"
SideloadQueryKey is the name of the query parameter that determines which entities should be sideloaded.
var StateQueryKey = "state"
StateQueryKey is the name of the query paramtere that determines which entity states should be returned.
Functions ¶
func ContextParams ¶
func ContextParams(context *ctx.Context) httprouter.Params
ContextParams returns the httprouter.Params for the context.
func MustSchema ¶
func MustSchemaFromFile ¶
func RespondWithData ¶
func RespondWithData(w http.ResponseWriter, r *http.Request, data interface{}, code int)
RespondWithData will use the default renderer to render the response.
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, r *http.Request, err error)
RespondWithError will return an error response with the appropriate message, and status codes set.
func RespondWithRenderedData ¶
func RespondWithRenderedData(renderer Renderer, w http.ResponseWriter, r *http.Request, data interface{}, code int)
RespondWithRenderedData will render the supplied data as a response.
func RespondWithStatusCode ¶
func RespondWithStatusCode(w http.ResponseWriter, r *http.Request, code int)
RespondWithStatusCode returns an empty response.
func SetContextCriteria ¶
SetContextCriteria sets the criteria against a context.
func SetContextParams ¶
func SetContextParams(context *ctx.Context, params httprouter.Params)
SetContextParams sets the supplied httprouter.Params on the context.
Types ¶
type APIError ¶
type APIError struct { Code int `json:"code,omitempty"` Description string `json:"description,omitempty"` Error string `json:"error"` Fields map[string]string `json:"fields,omitempty"` }
APIError represents an API error response. This will be passed to a renderer error method for conversion into an appropriate response.
type ActionHandler ¶
ActionHandler implementers are responsible for returning payload data for a request, along with a status code or error.
type ActionHandlerFunc ¶
ActionHandlerFunc wraps a function with the HandleAction signature to a full ActionHandler interface.
func (ActionHandlerFunc) HandleAction ¶
func (fn ActionHandlerFunc) HandleAction(context *ctx.Context) (interface{}, int, error)
HandleAction implements the ActionHander interface and simply calls the underlying function.
type ActionProcessor ¶
type ActionProcessor struct { SideloadEnabled bool MetricsRegistry metrics.Registry }
ActionProcessor handles an entire action lifecycle, from data retrieval through to unlocking, and responding.
func NewActionProcessor ¶
func NewActionProcessor() *ActionProcessor
func (*ActionProcessor) HTTPHandler ¶
func (p *ActionProcessor) HTTPHandler(typ, action string, handler ActionHandler) httprouter.Handle
HTTPHandler takes an ActionHandler and returns a http.Handler instance that can be used. The type and action are used to determine the context in several areas, such as transformers and metrics.
func (*ActionProcessor) HandleActionFunc ¶
func (p *ActionProcessor) HandleActionFunc(typ, action string, fn func(*ctx.Context) (interface{}, int, error)) httprouter.Handle
HandleActionFunc returns an http.Handler for the suppled action function. A type and action name are used in metrics and logging functions.
type Actor ¶
type Actor interface { // ActorInfo returns both the identifier and type of the actor. ActorInfo() (actorID string, actorType string) }
Actor represents a request actor, and is generally either an oauth client or user.
type AnnotatedError ¶
AnnotatedError defines an interface for additional metadata for an error. This is where you want to put all of your error data when it's more than just a single error case condition, for example all of the invalid fields in a bad update or create operation.
type Criteria ¶
type Criteria struct { // Sideload is a slice of related entities to sideload. Sideload []string // OrderColumn defines the order that collections should be ordered by. OrderColumn *string OrderAscending bool // From represents a time that entities should have been updated after. From *time.Time // Limit is the number of results in a collection Limit int // State is an array of item states to filter by State []string }
Criteria defines how results should be modified, or filtered.
func ContextCriteria ¶
ContextCriteria returns the criteria for the supplied context.
func RequestCriteria ¶
RequestCriteria generates a criteria instance from the request.
func (Criteria) ShouldSideload ¶
ShouldSideload returns true if the supplied name is in the sideload list.
type DescriptiveError ¶
type DescriptiveError interface {
ErrorDescription() string
}
DescriptiveError defines an interface for returning a human readable error description. It’s ok to use humour here, as these descriptions will be read by developers, or at least real people, and can often be read in a time of frustration. Be authentic with your descriptions, and good karma may come your way.
type Renderer ¶
var ( // DefaultRenderer is the renderer used by default. This can be changed at // runtime to a renderer that suits. // DefaultRenderer = render.JSONRenderer{} DefaultRenderer Renderer )
type Response ¶
type Response struct { Payload interface{} `json:"payload"` // A pointer is used here to allow empty maps to be returned. Sideload *map[string]map[string]interface{} `json:"related,omitempty"` }
Response represents a non error display response.
type StatusError ¶
type StatusError interface {
StatusCode() int
}
StatusError defines an interface for an error that also includes a custom http status code. Use this liberally to differentiate service errors from things like authentication, authorization or validation errors.
type StructuredLogsError ¶
StructuredLogsError defines an interface for additional metadata for an error. This metadata will be logged, but not output to the public error response.