rest

package
v0.0.0-...-c5756db Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = &ErrResponse{HTTPStatusCode: 404, StatusText: "Resource not found."}

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func Handler

func Handler(s stats.Service) chi.Router

Handler returns a chi router to be used in http.ListenAndServe.

func NewStatsListResponse

func NewStatsListResponse(stats []stats.Stat) []render.Renderer

NewStatsListResponse creates a response built from a slice of stats

func ParseQueryParams

func ParseQueryParams(next http.Handler) http.Handler

ParseQueryParams is a middleware that parses url query parameters passed in as part of the url. It will generate an injection safe SQL 'WHERE' query string and associated slice of values and add this to the context. @TODO: return error if values are missing.

Types

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type StatsListResponse

type StatsListResponse []*StatsResponse

StatsListResponse represents a response built from a slice of stats

type StatsResponse

type StatsResponse struct {
	stats.Stat
}

StatsResponse is the response payload for the Stats data model.

func NewStatsResponse

func NewStatsResponse(stat stats.Stat) *StatsResponse

NewStatsResponse generates a new stats response

func (*StatsResponse) Render

func (sr *StatsResponse) Render(w http.ResponseWriter, r *http.Request) error

Render satisfies the chi renderer interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL