Documentation ¶
Index ¶
- func IsAlreadyExists(err error) bool
- func IsBadCredentials(err error) bool
- func IsBadGateway(err error) bool
- func IsBadRequest(err error) bool
- func IsGone(err error) bool
- func IsInternalServiceError(err error) bool
- func IsMethodNotAllowed(err error) bool
- func IsNotFound(err error) bool
- func IsNotImplemented(err error) bool
- func IsPaymentRequired(err error) bool
- func IsPermissionDenied(err error) bool
- func IsThrottled(err error) bool
- func IsTimeout(err error) bool
- func IsTooLarge(err error) bool
- func IsUnavailable(err error) bool
- func IsUnexpected(err error) bool
- func IsUnsupportedFormat(err error) bool
- func Status(err error) int
- type Error
- type ErrorHandler
- type Group
- type StatusError
- func AlreadyExists(messageFormat string, args ...any) StatusError
- func BadCredentials(messageFormat string, args ...any) StatusError
- func BadGateway(messageFormat string, args ...any) StatusError
- func BadRequest(messageFormat string, args ...any) StatusError
- func Gone(messageFormat string, args ...any) StatusError
- func InternalServerError(messageFormat string, args ...any) StatusError
- func MethodNotAllowed(messageFormat string, args ...any) StatusError
- func New(status int, messageFormat string, args ...any) StatusError
- func NotFound(messageFormat string, args ...any) StatusError
- func NotImplemented(messageFormat string, args ...any) StatusError
- func PaymentRequired(messageFormat string, args ...any) StatusError
- func PermissionDenied(messageFormat string, args ...any) StatusError
- func Throttled(messageFormat string, args ...any) StatusError
- func Timeout(messageFormat string, args ...any) StatusError
- func TooLarge(messageFormat string, args ...any) StatusError
- func Unavailable(messageFormat string, args ...any) StatusError
- func Unexpected(messageFormat string, args ...any) StatusError
- func UnsupportedFormat(messageFormat string, args ...any) StatusError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶
IsAlreadyExists returns true if the underlying HTTP status code of 'err' is 409. This will be true for any error you created using the AlreadyExists() function.
func IsBadCredentials ¶
IsBadCredentials returns true if the underlying HTTP status code of 'err' is 401. This will be true for any error you created using the BadCredentials() function.
func IsBadGateway ¶
IsBadGateway returns true if the underlying HTTP status code of 'err' is 502. This will be true for any error you created using the BadGateway() function.
func IsBadRequest ¶
IsBadRequest returns true if the underlying HTTP status code of 'err' is 400. This will be true for any error you created using the BadRequest() function.
func IsGone ¶
IsGone returns true if the underlying HTTP status code of 'err' is 410. This will be true for any error you created using the Gone() function.
func IsInternalServiceError ¶
IsInternalServiceError returns true if the underlying HTTP status code of 'err' is 500. This will be true for any error you created using the InternalServiceError() function.
func IsMethodNotAllowed ¶
IsMethodNotAllowed returns true if the underlying HTTP status code of 'err' is 405. This will be true for any error you created using the MethodNotAllowed() function.
func IsNotFound ¶
IsNotFound returns true if the underlying HTTP status code of 'err' is 404. This will be true for any error you created using the NotFound() function.
func IsNotImplemented ¶
IsNotImplemented returns true if the underlying HTTP status code of 'err' is 501. This will be true for any error you created using the Throttled() function.
func IsPaymentRequired ¶
IsPaymentRequired returns true if the underlying HTTP status code of 'err' is 402. This will be tru for any error you created using the PaymentRequired() function.
func IsPermissionDenied ¶
IsPermissionDenied returns true if the underlying HTTP status code of 'err' is 403. This will be true for any error you created using the PermissionDenied() function.
func IsThrottled ¶
IsThrottled returns true if the underlying HTTP status code of 'err' is 429. This will be true for any error you created using the Throttled() function.
func IsTimeout ¶
IsTimeout returns true if the underlying HTTP status code of 'err' is 408. This will be true for any error you created using the Timeout() function.
func IsTooLarge ¶
IsTooLarge returns true if the underlying HTTP status code of 'err' is 413. This will be true for any error you created using the TooLarge() function.
func IsUnavailable ¶
IsUnavailable returns true if the underlying HTTP status code of 'err' is 503. This will be true for any error you created using the Unavailable() function.
func IsUnexpected ¶
IsUnexpected returns true if the underlying HTTP status code of 'err' is 500. This will be true for any error you created using the Unexpected() function.
func IsUnsupportedFormat ¶
IsUnsupportedFormat returns true if the underlying HTTP status code of 'err' is 415. This will be true for any error you created using the UnsupportedFormat() function.
Types ¶
type Error ¶ added in v0.1.4
type Error StatusError
Error is simply a shorthand for the fail package's StatusError that includes an HTTP status code w/ your error message.
type ErrorHandler ¶
type ErrorHandler func(err error)
ErrorHandler is the generic function signature for something that accepts errors that occur in the bowels of the framework. It gives you a chance to log or deal with them as you see fit. These are typically asynchronous things where you don't have any handle over the control flow, but you don't want to lose these events.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
A Group is a collection of goroutines working on subtasks that are part of the same overall task.
A zero Group is valid, has no limit on the number of active goroutines, and does not cancel on error.
func NewGroup ¶
NewGroup returns a new Group and an associated Context derived from ctx.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
func (*Group) Go ¶
Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.
The first call to return a non-nil error cancels the group's context, if the group was created by calling WithContext. The error will be returned by Wait.
type StatusError ¶
type StatusError struct { // Status is the HTTP status code that most closely describes this error. Status int `json:"Status"` // Message is the human-readable error message. Message string `json:"Message"` }
StatusError is an error that maintains not just an error message but an HTTP compatible status code indicating the type/class of error. It's useful for helping you figure out downstream if an occurred because the user didn't have rights or if some record did not exist.
func AlreadyExists ¶
func AlreadyExists(messageFormat string, args ...any) StatusError
AlreadyExists is a 409-style error that is used when attempting to create some record/resource, but there is already a duplicate instance in existence.
func BadCredentials ¶
func BadCredentials(messageFormat string, args ...any) StatusError
BadCredentials is a 401-style error that indicates that the caller either didn't provide credentials when necessary or they did, but the credentials were invalid for some reason. This corresponds to the HTTP "unauthorized" status, but we prefer this name because this type of failure has nothing to do with authorization, and it's more clear what aspect of the request has failed.
func BadGateway ¶
func BadGateway(messageFormat string, args ...any) StatusError
BadGateway is a 502-style error that indicates that some upstream resource was not available. Your code is working fine, but another service you're dependent on is not.
func BadRequest ¶
func BadRequest(messageFormat string, args ...any) StatusError
BadRequest is a 400-style error that indicates that some aspect of the request was either ill-formed or failed validation. This could be an ill-formed function parameter, a bad HTTP body, etc.
func Gone ¶
func Gone(messageFormat string, args ...any) StatusError
Gone is a 410-style error that is used to indicate that something used to exist, but doesn't anymore.
func InternalServerError ¶
func InternalServerError(messageFormat string, args ...any) StatusError
InternalServerError is a generic 500-style catch-all error for failures you don't know what to do with.
func MethodNotAllowed ¶
func MethodNotAllowed(messageFormat string, args ...any) StatusError
MethodNotAllowed is a 405-style error that indicates that the wrong HTTP method was used.
func New ¶
func New(status int, messageFormat string, args ...any) StatusError
New creates an error that maps directly to an HTTP status so if your method results in this error, it will result in the same 'status' in your HTTP response. While you can do this for more obscure HTTP failure statuses like "payment required", it's typically a better idea to use the error functions BadRequest(), PermissionDenied(), etc. as it provides proper status codes and results in more readable code.
func NotFound ¶
func NotFound(messageFormat string, args ...any) StatusError
NotFound is a 404-style error that indicates that some record/resource could not be located.
func NotImplemented ¶
func NotImplemented(messageFormat string, args ...any) StatusError
NotImplemented is a 501-style error that indicates that the resource/logic required to fulfill the request has not been added yet.
func PaymentRequired ¶
func PaymentRequired(messageFormat string, args ...any) StatusError
PaymentRequired is a 402-style error that indicates that you must provide payment to access the given resource or perform the given task. Greedy bastard :)
func PermissionDenied ¶
func PermissionDenied(messageFormat string, args ...any) StatusError
PermissionDenied is a 403-style error that indicates that the caller does not have rights/clearance to perform any part of the operation.
func Throttled ¶
func Throttled(messageFormat string, args ...any) StatusError
Throttled is a 429-style error that indicates that the caller has exceeded the number of requests, amount of resources, etc allowed over some time period. The failure should indicated to the caller that the failure is due to some throttle that prevented the operation from even occurring.
func Timeout ¶
func Timeout(messageFormat string, args ...any) StatusError
Timeout is a 408-style error that indicates that some operation exceeded its allotted time/deadline.
func TooLarge ¶
func TooLarge(messageFormat string, args ...any) StatusError
TooLarge is a 413-style error that is used to indicate that some resource/entity is too big.
func Unavailable ¶
func Unavailable(messageFormat string, args ...any) StatusError
Unavailable is a 503-style error that indicates that some aspect of the server/service is unavailable. This could be something like DB connection failures, some third party service being down, etc.
func Unexpected ¶
func Unexpected(messageFormat string, args ...any) StatusError
Unexpected is a generic 500-style catch-all error for failures you don't know what to do with. This is exactly the same as calling InternalServerError(), just more concise in your code.
func UnsupportedFormat ¶
func UnsupportedFormat(messageFormat string, args ...any) StatusError
UnsupportedFormat is a 415-style error that is used to indicate that the media/content type of some input is not valid. For instance, the user uploads an "image/bmp" but you only support PNG and JPG files.
func (StatusError) Error ¶
func (r StatusError) Error() string
Error returns the underlying error message.
func (StatusError) StatusCode ¶
func (r StatusError) StatusCode() int
StatusCode returns the most relevant HTTP-style status code describing this type of error.