Documentation ¶
Index ¶
- Variables
- func UnmarshalRequestBody(r *http.Request, j interface{}) error
- func UnmarshalRequestBytes(r *http.Request, b []byte, j interface{}) error
- func UnmarshalWithKind(kind OutputKind, b []byte, j interface{}) error
- func WriteAuto(output interface{}, err error, errCode ErrorCodes, r *http.Request, ...) error
- func WriteErr(err error, statusCode int, code ErrorCodes, r *http.Request, ...) error
- func WriteError(msg string, statusCode int, code ErrorCodes, r *http.Request, ...) error
- func WriteOutput(isError bool, statusCode int, output interface{}, r *http.Request, ...) error
- type APIError
- type Context
- type Error
- type ErrorCodes
- type OutputKind
- type ReqContext
- func (rc ReqContext) GetDecoder() decoder
- func (rc ReqContext) Unmarshal(body []byte, j interface{}) error
- func (rc ReqContext) ValidateBody(j interface{}, writeErr bool) error
- func (rc ReqContext) ValidateBytes(body []byte, j interface{}) error
- func (rc ReqContext) ValidateStruct(input interface{}) error
- func (rc ReqContext) WriteAuto(output interface{}, error error, errCode ErrorCodes)
- func (rc ReqContext) WriteErr(err error, errCode ErrorCodes)
- func (rc ReqContext) WriteError(msg string, errCode ErrorCodes, details ...interface{})
- func (rc ReqContext) WriteNotFound(errCode ErrorCodes)
- func (rc ReqContext) WriteOutput(output interface{}, statusCode int)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyBody = NewError("Body was empty", CodeErrInputValidation) ErrIDNonValid = NewError("Id was not valid", CodeErrIDNonValid) ErrIDTooLong = NewError("Id was too long", CodeErrIDTooLong) ErrIDEmpty = NewError("Id was empty", CodeErrIDEmpty) )
Functions ¶
func UnmarshalRequestBody ¶
func UnmarshalRequestBytes ¶
func UnmarshalWithKind ¶
func UnmarshalWithKind(kind OutputKind, b []byte, j interface{}) error
func WriteAuto ¶
func WriteAuto(output interface{}, err error, errCode ErrorCodes, r *http.Request, rw http.ResponseWriter) error
Deprectated
func WriteErr ¶
func WriteErr(err error, statusCode int, code ErrorCodes, r *http.Request, rw http.ResponseWriter) error
func WriteError ¶
func WriteError(msg string, statusCode int, code ErrorCodes, r *http.Request, rw http.ResponseWriter, details ...interface{}) error
func WriteOutput ¶
Types ¶
type APIError ¶
type APIError struct { Details interface{} `json:"details,omitempty"` Err Error `json:"error"` InternalError error `json:"-"` StatusCode int `json:"-"` }
func (APIError) ErrHttpStatus ¶ added in v0.8.0
type Context ¶
func (*Context) NewReqContext ¶
func (c *Context) NewReqContext(rw http.ResponseWriter, r *http.Request) ReqContext
type Error ¶
type Error struct { Code ErrorCodes `json:"code,omitempty"` Message string `json:"error,omitempty"` }
func NewError ¶
func NewError(msg string, code ErrorCodes) Error
type ErrorCodes ¶
type ErrorCodes string
const ( CodeErrMethodNotAllowed ErrorCodes = "Error: HTTP-Method is not allowed" CodeErrNotImplemented ErrorCodes = "Error: Not implemented" CodeErrNoRoute ErrorCodes = "Error: No route matched for this http-path" CodeErrReadBody ErrorCodes = "Error: Failed to read body" CodeErrMarshal ErrorCodes = "Error: Failed to marshal" CodeErrUnmarshal ErrorCodes = "Error: Failed to unmarshal" CodeErrJmesPath ErrorCodes = "Error: JmesPath" CodeErrJmesPathMarshal ErrorCodes = "Error: JmesPathMarshal" CodeErrPasswordHashing ErrorCodes = "Error: Password-creation" CodeErrUnknown ErrorCodes = "Error: Unknown" CodeErrTemplating ErrorCodes = "Error: Templating" CodeErrRequestEntityTooLarge ErrorCodes = "Error: Request Entity too large" CodeErrInputValidation ErrorCodes = "Error: General input validation" CodeErrMissingBody ErrorCodes = "Error: No body" CodeErrIDNonValid ErrorCodes = "Error: ID not valid" CodeErrIDTooLong ErrorCodes = "Error: ID is too long" CodeErrIDEmpty ErrorCodes = "Error: ID was Empty" CodeErrAuthenticationRequired ErrorCodes = "Error: Authentication required" CodeErrAuthoriziationFailed ErrorCodes = "Error: Authorization failed" CodeErrAuthoriziation ErrorCodes = "Error: Authorization missing" CodeErrLocale ErrorCodes = "Error: Locale error" CodeErrUser ErrorCodes = "Error: User error" CodeErrProject ErrorCodes = "Error: Project error" CodeErrSnapshot ErrorCodes = "Error: Snapshot error" CodeErrReportMissing ErrorCodes = "Error: Report missing" CodeErrTranslation ErrorCodes = "Error: Translation error" CodeErrCategory ErrorCodes = "Error: Category error" CodeErrTranslationValue ErrorCodes = "Error: TranslationValue error" CodeErrOrganization ErrorCodes = "Error: Organization error" CodeErrOrganizationNotFound ErrorCodes = "Error: Organization not found" CodeErrImport ErrorCodes = "Error: Import error" CodeErrNotFoundLocale ErrorCodes = "Error: Locale not found" CodeErrNotFoundProject ErrorCodes = "Error: Project not found" CodeErrNotFoundTranslation ErrorCodes = "Error: Translation not found" CodeErrNotFoundUser ErrorCodes = "Error: User not found" CodeErrDBCreateLocale ErrorCodes = "Error: Database Create Locale" CodeErrDBCreateUser ErrorCodes = "Error: Database Create User" CodeErrCreateProject ErrorCodes = "Error: Database Create Project" CodeErrCreateTranslation ErrorCodes = "Error: Database Create Translation" CodeErrCreateCategory ErrorCodes = "Error: Database Create Category" CodeErrCreateOrganization ErrorCodes = "Error: Database Create Organization" CodeErrCreateTranslationValue ErrorCodes = "Error: Database Create TranslationValue" CodeErrDBUpdateLocale ErrorCodes = "Error: Database Update Locale" CodeErrUpdateProject ErrorCodes = "Error: Database Update Project" CodeErrUpdateTranslation ErrorCodes = "Error: Database Update Translation" CodeErrUpdateCategory ErrorCodes = "Error: Database Update Category" CodeErrUpdateOrganization ErrorCodes = "Error: Database Update Organization" CodeErrUpdateTranslationValue ErrorCodes = "Error: Database Update TranslationValue" )
type OutputKind ¶
type OutputKind = int
const ( OutputJson OutputKind = iota + 1 OutputYaml OutputToml )
func WantedOutputFormat ¶
func WantedOutputFormat(r *http.Request) OutputKind
attempts to guess at what kind of output the user most likely wants
type ReqContext ¶
type ReqContext struct { Context *Context Req *http.Request L logger.AppLogger Rw http.ResponseWriter ContentKind OutputKind Accept OutputKind RemoteIP string }
Deprecated. The useful methods here should be returned into structs
func NewReqContext ¶
func NewReqContext(context *Context, req *http.Request, rw http.ResponseWriter) ReqContext
func (ReqContext) GetDecoder ¶
func (rc ReqContext) GetDecoder() decoder
func (ReqContext) Unmarshal ¶
func (rc ReqContext) Unmarshal(body []byte, j interface{}) error
func (ReqContext) ValidateBody ¶
func (rc ReqContext) ValidateBody(j interface{}, writeErr bool) error
Reads the requests body, and validates it. with writeErr = true, upon validation error it will write the error to the body. In this case, the caller should simply return
func (ReqContext) ValidateBytes ¶
func (rc ReqContext) ValidateBytes(body []byte, j interface{}) error
Will perform validation and write errors to responsewriter if validation failed. If err is non-nill, the caller should simply return
func (ReqContext) ValidateStruct ¶
func (rc ReqContext) ValidateStruct(input interface{}) error
func (ReqContext) WriteAuto ¶
func (rc ReqContext) WriteAuto(output interface{}, error error, errCode ErrorCodes)
func (ReqContext) WriteErr ¶
func (rc ReqContext) WriteErr(err error, errCode ErrorCodes)
func (ReqContext) WriteError ¶
func (rc ReqContext) WriteError(msg string, errCode ErrorCodes, details ...interface{})
func (ReqContext) WriteNotFound ¶
func (rc ReqContext) WriteNotFound(errCode ErrorCodes)
func (ReqContext) WriteOutput ¶
func (rc ReqContext) WriteOutput(output interface{}, statusCode int)
Click to show internal directories.
Click to hide internal directories.