Documentation
¶
Index ¶
- Variables
- func CtxGetEndpoint(ctx context.Context) (*server.Endpoint, bool)
- func CtxMustGetID(ctx context.Context) string
- func CtxSetID(ctx context.Context, id string) context.Context
- func ErrAccountAlreadyExists() *codec.Error
- func ErrAccountDisabled() *codec.Error
- func ErrBadRequest() *codec.Error
- func ErrEndpointForbidden() *codec.Error
- func ErrForbiddenAuthorize() *codec.Error
- func ErrForbiddenOperation() *codec.Error
- func ErrHashMismatch() *codec.Error
- func ErrHeadersNotSupported() *codec.Error
- func ErrIDConflict() *codec.Error
- func ErrInputOutOfRange() *codec.Error
- func ErrInsufficientAccountPermissions() *codec.Error
- func ErrInternalError() *codec.Error
- func ErrInvalidAuthenticationInfo() *codec.Error
- func ErrInvalidAuthorizationHeader() *codec.Error
- func ErrInvalidCredentials() *codec.Error
- func ErrInvalidHeaderValue() *codec.Error
- func ErrInvalidInput() *codec.Error
- func ErrInvalidJSONDocument() *codec.Error
- func ErrInvalidJSONFieldName() *codec.Error
- func ErrInvalidJSONFieldValue() *codec.Error
- func ErrInvalidQueryParameter() *codec.Error
- func ErrInvalidResourceName() *codec.Error
- func ErrInvalidURI() *codec.Error
- func ErrLanguageHeaderNotAcceptable() *codec.Error
- func ErrLanguageNotAcceptable() *codec.Error
- func ErrMetadataTooLarge() *codec.Error
- func ErrMethodNotAllowed() *codec.Error
- func ErrMissingRequiredHeader() *codec.Error
- func ErrMissingRequiredModelField() *codec.Error
- func ErrMissingRequiredQueryParameter() *codec.Error
- func ErrNotAcceptable() *codec.Error
- func ErrOperationTimedOut() *codec.Error
- func ErrQueryParameterValueOutOfRange() *codec.Error
- func ErrRequestBodyTooLarge() *codec.Error
- func ErrResourceAlreadyExists() *codec.Error
- func ErrResourceNotFound() *codec.Error
- func ErrServiceUnavailable() *codec.Error
- func ErrTooManyOperationsPerAccount() *codec.Error
- func ErrTypeConflict() *codec.Error
- func ErrUnsupportedField() *codec.Error
- func ErrUnsupportedFilterOperator() *codec.Error
- func ErrUnsupportedHeader() *codec.Error
- func ErrUnsupportedQueryParameter() *codec.Error
- func ErrWarningNotification() *codec.Error
- func GetCodec(ctx context.Context) (codec.Codec, bool)
- func MapError(err error) []*codec.Error
- func MidStoreEndpoint(endpoint *server.Endpoint) server.Middleware
- func SetCodec(ctx context.Context, c codec.Codec) context.Context
- func Wrap(next http.Handler) httprouter.Handle
- type ErrFunc
- type ErrorMapper
- type QualityValue
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
var DefaultErrorMapper = &ErrorMapper{ errors.ErrInternal: ErrInternalError, codec.ErrMarshal: ErrInternalError, codec.ErrUnmarshalDocument: ErrInvalidJSONDocument, codec.ErrCodec: ErrInvalidInput, codec.ErrUnmarshal: ErrInvalidInput, codec.ErrUnmarshalFieldValue: ErrInvalidJSONFieldValue, codec.ErrUnmarshalFieldName: ErrInvalidJSONFieldName, query.ErrViolation: ErrInvalidJSONFieldValue, filter.ErrFilter: ErrInvalidQueryParameter, filter.ErrFilterCollection: ErrInvalidResourceName, query.ErrFieldValue: ErrInvalidJSONFieldValue, query.ErrInvalidParameter: ErrInvalidQueryParameter, query.ErrInvalidSort: ErrInvalidQueryParameter, query.ErrInvalidFieldSet: ErrInvalidQueryParameter, query.ErrNoFieldsInFieldSet: ErrInvalidQueryParameter, query.ErrViolationUnique: ErrResourceAlreadyExists, query.ErrViolationCheck: ErrInvalidJSONFieldValue, query.ErrViolationNotNull: ErrInvalidInput, mapping.ErrModel: ErrInternalError, mapping.ErrRelation: ErrInternalError, mapping.ErrFieldValue: ErrInvalidJSONFieldValue, mapping.ErrFieldNotParser: ErrInvalidQueryParameter, mapping.ErrFieldNotNullable: ErrForbiddenOperation, mapping.ErrModelNotFound: ErrResourceNotFound, mapping.ErrInvalidRelationField: ErrInvalidQueryParameter, server.ErrHeaderNotAcceptable: ErrNotAcceptable, server.ErrUnsupportedHeader: ErrUnsupportedHeader, server.ErrMissingRequiredHeader: ErrMissingRequiredHeader, server.ErrHeaderValue: ErrInvalidHeaderValue, auth.ErrAccountNotFound: ErrInvalidAuthenticationInfo, auth.ErrAccountAlreadyExists: ErrAccountAlreadyExists, auth.ErrInvalidUsername: ErrInvalidAuthenticationInfo, auth.ErrInvalidSecret: ErrInvalidAuthenticationInfo, auth.ErrInvalidPassword: ErrInvalidAuthenticationInfo, auth.ErrTokenRevoked: ErrInvalidAuthenticationInfo, auth.ErrTokenNotValidYet: ErrInvalidAuthenticationInfo, auth.ErrTokenExpired: ErrInvalidAuthenticationInfo, auth.ErrForbidden: ErrForbiddenAuthorize, auth.ErrInvalidRole: ErrForbiddenAuthorize, auth.ErrAuthorizationHeader: ErrInvalidAuthorizationHeader, }
DefaultErrorMapper is the default error classification mapper.
var IDKey = &idKeyStruct{}
IDKey is the context key that should match the value of 'ID' for the handlers requests.
Functions ¶
func CtxGetEndpoint ¶
CtxGetEndpoint gets the endpoint stored in the given 'ctx' context.
func CtxMustGetID ¶
CtxMustGetID gets ID from the context or panics if no id is found there. ID should be in the raw string form.
func ErrAccountAlreadyExists ¶
ErrAccountAlreadyExists creating account failed - user already exists.
func ErrAccountDisabled ¶
ErrAccountDisabled provided account is disabled.
func ErrBadRequest ¶
ErrBadRequest is the API error thrown on bad request
func ErrEndpointForbidden ¶
ErrEndpointForbidden forbidden access above given API endpoint.
func ErrForbiddenAuthorize ¶
ErrForbidden server understood the request but refuses to authorize it.
func ErrForbiddenOperation ¶
ErrForbiddenOperation server understood the request but current operation is not allowed.
func ErrHashMismatch ¶
ErrHashMismatch returns when the hash value specified in the request didn't match the one stored/computed by the server.
func ErrHeadersNotSupported ¶
ErrHeadersNotSupported errors thrown when the provided HTTP headers are not supported by the server
func ErrIDConflict ¶
ErrIDConflict defines an error when the primary field value doesn't match endpoint's defined id.
func ErrInputOutOfRange ¶
ErrInputOutOfRange one of the request inputs were out of range.
func ErrInsufficientAccountPermissions ¶
ErrInsufficientAccountPermissions provided account has insufficient permissions for given request.
func ErrInternalError ¶
ErrInternalError server encountered internal error.
func ErrInvalidAuthenticationInfo ¶
ErrInvalidAuthenticationInfo defines the error when the authentication fails.
func ErrInvalidAuthorizationHeader ¶
ErrInvalidAuthorizationHeader server failed to authenticate the request due to invalid authorization header.
func ErrInvalidCredentials ¶
ErrInvalidCredentials provided invalid account credentials - access denied.
func ErrInvalidHeaderValue ¶
ErrInvalidHeaderValue responded when some HTTP header was not in a valid format.
func ErrInvalidInput ¶
ErrInvalidInput returned when provided request input is not valid.
func ErrInvalidJSONDocument ¶
ErrInvalidJSONDocument error returned when the specified JSON structure is not syntactically valid.
func ErrInvalidJSONFieldName ¶
ErrInvalidJSONFieldName error returned when one or more of the specified JSON fields was not in a correct format.
func ErrInvalidJSONFieldValue ¶
ErrInvalidJSONFieldValue error returned when one or more of the specified JSON fields was not in a correct format.
func ErrInvalidQueryParameter ¶
ErrInvalidQueryParameter one of the query parameters has invalid value or format.
func ErrInvalidResourceName ¶
ErrInvalidResourceName defines an error when the specified resource name is not valid.
func ErrInvalidURI ¶
ErrInvalidURI error returned when the URI is not recognized by the server.
func ErrLanguageHeaderNotAcceptable ¶
ErrLanguageHeaderNotAcceptable provided request headers contains not supported language.
func ErrLanguageNotAcceptable ¶
ErrLanguageNotAcceptable languages provided in the request are not supported.
func ErrMetadataTooLarge ¶
ErrMetadataTooLarge the size of the specified metadata exceeds the limits.
func ErrMethodNotAllowed ¶
ErrMethodNotAllowed given method is not allowed for the specified URI
func ErrMissingRequiredHeader ¶
ErrMissingRequiredHeader one of the required HTTP headers were not specified in the request.
func ErrMissingRequiredModelField ¶
ErrMissingRequiredModelField one of the required model fields were not specified in the request body
func ErrMissingRequiredQueryParameter ¶
ErrMissingRequiredQueryParameter returns when one or more of the query parameter is missing for the request.
func ErrNotAcceptable ¶
ErrNotAcceptable one of the header contains values that are not possible to get the response by the server.
func ErrOperationTimedOut ¶
ErrOperationTimedOut the operation could not be completed within the permitted time.
func ErrQueryParameterValueOutOfRange ¶
ErrQueryParameterValueOutOfRange one of the specified query parameters in the request URI is outside the permissible range.
func ErrRequestBodyTooLarge ¶
ErrRequestBodyTooLarge the size of the request body exceeds the maximum permitted size.
func ErrResourceAlreadyExists ¶
ErrResourceAlreadyExists the specified resource already exists.
func ErrResourceNotFound ¶
ErrResourceNotFound provided resource doesn't exists.
func ErrServiceUnavailable ¶
ErrServiceUnavailable the server is currently unable to receive requests.
func ErrTooManyOperationsPerAccount ¶
ErrTooManyOperationsPerAccount too many requests for given account.
func ErrTypeConflict ¶
ErrTypeConflict defines an error when the data 'type' doesn't match endpoint's defined 'type'.
func ErrUnsupportedField ¶
ErrUnsupportedField one of the fields specified in the request is not supported.
func ErrUnsupportedFilterOperator ¶
ErrUnsupportedFilterOperator one of the filter operators is not supported.
func ErrUnsupportedHeader ¶
ErrUnsupportedHeader one of the HTTP headers specified in the request is not supported.
func ErrUnsupportedQueryParameter ¶
ErrUnsupportedQueryParameter one of the query parameters in the request URI is not supported.
func ErrWarningNotification ¶
ErrWarningNotification warns on response with some value.
func MapError ¶
MapError maps the 'err' input error into slice of 'Error'. The function uses DefaultErrorMapper for error mapping. The logic is the same as for DefaultErrorMapper.Errors method.
func MidStoreEndpoint ¶
func MidStoreEndpoint(endpoint *server.Endpoint) server.Middleware
MidStoreEndpoint is a middleware that stores the endpoint in the request context.
Types ¶
type ErrorMapper ¶
ErrorMapper is the neuron errors classification mapper. It creates the 'Error' from the provided error.
func (*ErrorMapper) Errors ¶
func (c *ErrorMapper) Errors(err error) []*codec.Error
Errors gets the slice of 'Error' from the provided 'err' error. The mapping is based on the 'most specific classification first' method. If the error is 'errors.ClassError' the function gets it's class. The function checks classification occurrence based on the priority:
- Class
- Minor
- Major
If no mapping is provided for given classification - an internal error is returned.
type QualityValue ¶
QualityValue is the structure that contains quality - value pair.
func ParseAcceptEncodingHeader ¶
func ParseAcceptEncodingHeader(header http.Header) []QualityValue
ParseAcceptEncodingHeader parses 'Accept-Encoding' header values sorted by it's quality.
func ParseAcceptHeader ¶
func ParseAcceptHeader(header http.Header) []QualityValue
ParseAcceptHeader parses 'Accept' header values sorted by it's quality.
type ResponseWriter ¶
type ResponseWriter struct { Status int TempWriter io.Writer Buffer *bytes.Buffer ResponseWriter http.ResponseWriter }
ResponseWriter is a wrapper implementation for the http.ResponseWriter. It allows to have buffered writer and status. It needs to be used in a middleware so that it could manipulate the output with some compressor or react differently on panic. Look at middleware.ResponseWriter how it is used.
func (*ResponseWriter) Header ¶
func (r *ResponseWriter) Header() http.Header
Header implements http.ResponseWriter.
func (*ResponseWriter) Write ¶
func (r *ResponseWriter) Write(bytes []byte) (int, error)
Write implements io.Writer.
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(statusCode int)
WriteHeader implements http.ResponseWriter.