Documentation
¶
Index ¶
- Variables
- func HTTPErrorMatcher(httpError *HTTPError) routing.Matcher
- func ResourceMatcher(resource Resource) routing.Matcher
- func ResourcesMatcher(prefix string, collection Resources) routing.Matcher
- type HTTPError
- type LimitedResource
- type LimitedResources
- type Link
- type Resource
- type ResourceBase
- func (ResourceBase) BeforeFilter(resp http.ResponseWriter, req *http.Request) bool
- func (ResourceBase) Delete(request *http.Request) (interface{}, error)
- func (ResourceBase) Get(request *http.Request) (interface{}, error)
- func (ResourceBase) Patch(request *http.Request) (interface{}, error)
- func (ResourceBase) Post(request *http.Request) (interface{}, error)
- func (ResourceBase) SubResources() routing.Matcher
- func (ResourceBase) Update(request *http.Request) (interface{}, error)
- type Resources
- type ResourcesBase
- type ResponseEncoder
- type ResponseEncoderChooser
- type Result
- type StaticResource
Constants ¶
This section is empty.
Variables ¶
var HTTPBadRequest = &HTTPError{
Code: 400,
Type: "https://httpstatus.es/400",
Message: "Bad request",
}
HTTPBadRequest is a HTTP bad request 400
var HTTPConflict = &HTTPError{
Code: 409,
Type: "https://httpstatus.es/409",
Message: "Conflict",
}
HTTPConflict is a HTTP conflict 409
var HTTPForbidden = &HTTPError{
Code: 403,
Type: "https://httpstatus.es/403",
Message: "Forbidden",
}
HTTPForbidden is a HTTP forbidden 403
var HTTPMethodNotAllowed = &HTTPError{
Code: 405,
Type: "https://httpstatus.es/405",
Message: "Method not allowed",
}
HTTPMethodNotAllowed is a HTTP method not allowed 405
var HTTPNotFound = &HTTPError{
Code: 404,
Type: "https://httpstatus.es/404",
Message: "Not found",
}
HTTPNotFound is a HTTP not found 404
Code: 401,
Type: "https://httpstatus.es/401",
Message: "Unauthorized",
}HTTPUnauthorized is a HTTP Unauthorized 401
var JsonResponseEncoder jsonResponseEncoder
var XmlResponseEncoder xmlResponseEncoder
Functions ¶
func HTTPErrorMatcher ¶
HTTPErrorMatcher is a routing.Matcher that always response with a given HTTPError. Usually useful at the end of a routing chain as catch all for MethodNotAllowed or NotFound-
func ResourceMatcher ¶
Types ¶
type HTTPError ¶
type HTTPError struct { Code int `json:"code" xml:"code"` Type string `json:"type" xml:"type"` Message string `json:"message" xml:"message"` Details string `json:"details,omitempty" xml:"details,omitempty"` }
HTTPError is an error result of a HTTP/REST operation. Implements the Error interface.
func HTTPInternalServerError ¶
HTTPInternalServerError wraps an arbitrary Error as HTTP internal server error 500
func WrapError ¶
WrapError wrap a generic error as HTTPError. If err already is a HTTPError it will be left intact, otherwise the error will be mapped to InternalServerError
func (*HTTPError) Send ¶
func (e *HTTPError) Send(response http.ResponseWriter, encoder ResponseEncoder)
Send the HTTPError the a http.ResponseWriter
func (*HTTPError) WithDetails ¶
WithDetails creates a new HTTPError with extra detail message
type LimitedResource ¶
type LimitedResource struct { ResourceBase RequestSizeLimit int64 }
func (LimitedResource) BeforeFilter ¶
func (r LimitedResource) BeforeFilter(resp http.ResponseWriter, req *http.Request) bool
type LimitedResources ¶
type LimitedResources struct { ResourcesBase RequestSizeLimit int64 }
func (LimitedResources) BeforeFilter ¶
func (r LimitedResources) BeforeFilter(resp http.ResponseWriter, req *http.Request) bool
type Link ¶
type Link struct { Href string `json:"href" xml:"href"` Method string `json:"method,omitempty" xml:"method,omitempty"` }
Link is the minimal implementation of a HATOAS link
type Resource ¶
type Resource interface { BeforeFilter(resp http.ResponseWriter, req *http.Request) bool Self() Link Get(request *http.Request) (interface{}, error) Post(request *http.Request) (interface{}, error) Patch(request *http.Request) (interface{}, error) Update(request *http.Request) (interface{}, error) Delete(request *http.Request) (interface{}, error) SubResources() routing.Matcher }
func NewStaticResource ¶
type ResourceBase ¶
type ResourceBase struct{}
func (ResourceBase) BeforeFilter ¶
func (ResourceBase) BeforeFilter(resp http.ResponseWriter, req *http.Request) bool
func (ResourceBase) SubResources ¶
func (ResourceBase) SubResources() routing.Matcher
type ResourcesBase ¶
type ResourcesBase struct{}
func (ResourcesBase) BeforeFilter ¶
func (ResourcesBase) BeforeFilter(resp http.ResponseWriter, req *http.Request) bool
func (ResourcesBase) FindById ¶
func (ResourcesBase) FindById(id string) (interface{}, error)
type ResponseEncoder ¶
type ResponseEncoder interface { ContentType() string Encode(output io.Writer, data interface{}) error }
func StdResponseEncoderChooser ¶
func StdResponseEncoderChooser(request *http.Request) ResponseEncoder
type ResponseEncoderChooser ¶
type ResponseEncoderChooser func(*http.Request) ResponseEncoder
type Result ¶
Result allows a better control of the response of a REST operation. This should be used if a REST handler needs to modify HTTP headers or has a specific status.
func (*Result) Send ¶
func (r *Result) Send(resp http.ResponseWriter, encoder ResponseEncoder) error
func (*Result) WithStatus ¶
WithStatus modifies the HTTP status of a response
type StaticResource ¶
type StaticResource struct { ResourceBase // contains filtered or unexported fields }
func (StaticResource) Self ¶
func (r StaticResource) Self() Link