Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithRequester(ctx context.Context, requester Requester) context.Context
- func ErrorResponse(ctx *gin.Context, err error)
- func NewDataResponse(data interface{}) *successResponse
- func NewRequester(id, uid string) *requesterData
- func NewResponse(data, paging, extra interface{}) *successResponse
- func NewSubscriberEngine(name string, ps PubSubComponent, ac appctx.AppContext) *subscriberEngine
- func SuccessResponse(ctx *gin.Context, data *successResponse)
- type CacheComponent
- type DBMigrationComponent
- type DebugCarrier
- type DefaultError
- func (e DefaultError) Debug() string
- func (e DefaultError) Details() map[string]interface{}
- func (e DefaultError) Error() string
- func (e DefaultError) Format(s fmt.State, verb rune)
- func (e DefaultError) GRPCStatus() *status.Status
- func (e DefaultError) ID() string
- func (e DefaultError) Is(err error) bool
- func (e DefaultError) Reason() string
- func (e DefaultError) RequestID() string
- func (e *DefaultError) StackTrace() (trace errors.StackTrace)
- func (e DefaultError) Status() string
- func (e DefaultError) StatusCode() int
- func (e DefaultError) Unwrap() error
- func (e DefaultError) WithDebug(debug string) *DefaultError
- func (e DefaultError) WithDebugf(debug string, args ...interface{}) *DefaultError
- func (e DefaultError) WithDetail(key string, detail interface{}) *DefaultError
- func (e DefaultError) WithDetailf(key string, message string, args ...interface{}) *DefaultError
- func (e DefaultError) WithError(message string) *DefaultError
- func (e DefaultError) WithErrorf(message string, args ...interface{}) *DefaultError
- func (e DefaultError) WithID(id string) *DefaultError
- func (e DefaultError) WithReason(reason string) *DefaultError
- func (e DefaultError) WithReasonf(reason string, args ...interface{}) *DefaultError
- func (e *DefaultError) WithTrace(err error) *DefaultError
- func (e DefaultError) WithWrap(err error) *DefaultError
- func (e *DefaultError) Wrap(err error)
- type DetailsCarrier
- type EmailComponent
- type GRPCClientComponent
- type GRPCServerComponent
- type GinComponent
- type GormDBComponent
- type GroupSubJob
- type IDCarrier
- type Image
- type Images
- type Paging
- type PubSubComponent
- type ReasonCarrier
- type RedisDBComponent
- type RequestIDCarrier
- type Requester
- type SQLModel
- type SimpleUser
- type StatusCarrier
- type StatusCodeCarrier
- type StorageComponent
- type SubJob
- type TokenMakerComponent
Constants ¶
View Source
const KeyRequester = "requester"
Variables ¶
View Source
var ErrBadRequest = DefaultError{ StatusField: http.StatusText(http.StatusBadRequest), ErrorField: "The request was invalid or contained malformed parameters", CodeField: http.StatusBadRequest, GRPCCodeField: codes.InvalidArgument, }
View Source
var ErrConflict = DefaultError{ StatusField: http.StatusText(http.StatusConflict), ErrorField: "A conflict occurred with the current state of the resource", CodeField: http.StatusConflict, GRPCCodeField: codes.FailedPrecondition, }
View Source
var ErrForbidden = DefaultError{ StatusField: http.StatusText(http.StatusForbidden), ErrorField: "Access to the requested page or resource is forbidden", CodeField: http.StatusForbidden, GRPCCodeField: codes.PermissionDenied, }
View Source
var ErrInternalServerError = DefaultError{ StatusField: http.StatusText(http.StatusInternalServerError), ErrorField: "An internal server error occurred. Please try again later", CodeField: http.StatusInternalServerError, GRPCCodeField: codes.Internal, }
View Source
var ErrNotFound = DefaultError{ StatusField: http.StatusText(http.StatusNotFound), ErrorField: "The requested page or resource could not be found", CodeField: http.StatusNotFound, GRPCCodeField: codes.NotFound, }
View Source
var ErrTimeout = DefaultError{ StatusField: http.StatusText(http.StatusRequestTimeout), ErrorField: "The request timed out", CodeField: http.StatusRequestTimeout, GRPCCodeField: codes.DeadlineExceeded, }
View Source
http.StatusText(http.StatusUnauthorized), ErrorField: "Access denied. Please authenticate with valid credentials", CodeField: http.StatusUnauthorized, GRPCCodeField: codes.Unauthenticated, }StatusField:
View Source
var ErrUnsupportedMediaType = DefaultError{ StatusField: http.StatusText(http.StatusUnsupportedMediaType), ErrorField: "The media type of the requested resource is not supported", CodeField: http.StatusUnsupportedMediaType, GRPCCodeField: codes.InvalidArgument, }
Functions ¶
func ContextWithRequester ¶
func ErrorResponse ¶
func NewDataResponse ¶
func NewDataResponse(data interface{}) *successResponse
func NewRequester ¶
func NewRequester(id, uid string) *requesterData
func NewResponse ¶
func NewResponse(data, paging, extra interface{}) *successResponse
func NewSubscriberEngine ¶
func NewSubscriberEngine(name string, ps PubSubComponent, ac appctx.AppContext) *subscriberEngine
func SuccessResponse ¶
Types ¶
type CacheComponent ¶
type DBMigrationComponent ¶
type DBMigrationComponent interface { MigrateUp() MigrateDown() }
type DebugCarrier ¶
type DebugCarrier interface { // Debug returns debugging information for the error, if applicable. Debug() string }
DebugCarrier can be implemented by an error to support error contexts.
type DefaultError ¶
type DefaultError struct { // The error ID // // Useful when trying to identify various errors in application logic. IDField string `json:"id,omitempty"` // The status code // // example: 404 CodeField int `json:"code,omitempty"` // The status description // // example: Not Found StatusField string `json:"status,omitempty"` // The request ID // // The request ID is often exposed internally in order to trace // errors across service architectures. This is often a UUID. // // example: d7ef54b1-ec15-46e6-bccb-524b82c035e6 RIDField string `json:"request,omitempty"` // A human-readable reason for the error // // example: User with ID 1234 does not exist. ReasonField string `json:"reason,omitempty"` // Debug information // // This field is often not exposed to protect against leaking // sensitive information. // // example: SQL field "foo" is not a bool. DebugField string `json:"debug,omitempty"` // Further error details DetailsField map[string]interface{} `json:"details,omitempty"` // Error message // // The error's message. // // example: The resource could not be found // required: true ErrorField string `json:"message"` GRPCCodeField codes.Code `json:"-"` // contains filtered or unexported fields }
func ToDefaultError ¶
func ToDefaultError(err error, requestID string) *DefaultError
func (DefaultError) Debug ¶
func (e DefaultError) Debug() string
func (DefaultError) Details ¶
func (e DefaultError) Details() map[string]interface{}
func (DefaultError) Error ¶
func (e DefaultError) Error() string
func (DefaultError) GRPCStatus ¶
func (e DefaultError) GRPCStatus() *status.Status
func (DefaultError) ID ¶
func (e DefaultError) ID() string
func (DefaultError) Is ¶
func (e DefaultError) Is(err error) bool
func (DefaultError) Reason ¶
func (e DefaultError) Reason() string
func (DefaultError) RequestID ¶
func (e DefaultError) RequestID() string
func (*DefaultError) StackTrace ¶
func (e *DefaultError) StackTrace() (trace errors.StackTrace)
StackTrace returns the error's stack trace.
func (DefaultError) Status ¶
func (e DefaultError) Status() string
func (DefaultError) StatusCode ¶
func (e DefaultError) StatusCode() int
func (DefaultError) Unwrap ¶
func (e DefaultError) Unwrap() error
func (DefaultError) WithDebug ¶
func (e DefaultError) WithDebug(debug string) *DefaultError
func (DefaultError) WithDebugf ¶
func (e DefaultError) WithDebugf(debug string, args ...interface{}) *DefaultError
func (DefaultError) WithDetail ¶
func (e DefaultError) WithDetail(key string, detail interface{}) *DefaultError
func (DefaultError) WithDetailf ¶
func (e DefaultError) WithDetailf(key string, message string, args ...interface{}) *DefaultError
func (DefaultError) WithError ¶
func (e DefaultError) WithError(message string) *DefaultError
func (DefaultError) WithErrorf ¶
func (e DefaultError) WithErrorf(message string, args ...interface{}) *DefaultError
func (DefaultError) WithID ¶
func (e DefaultError) WithID(id string) *DefaultError
func (DefaultError) WithReason ¶
func (e DefaultError) WithReason(reason string) *DefaultError
func (DefaultError) WithReasonf ¶
func (e DefaultError) WithReasonf(reason string, args ...interface{}) *DefaultError
func (*DefaultError) WithTrace ¶
func (e *DefaultError) WithTrace(err error) *DefaultError
func (DefaultError) WithWrap ¶
func (e DefaultError) WithWrap(err error) *DefaultError
func (*DefaultError) Wrap ¶
func (e *DefaultError) Wrap(err error)
type DetailsCarrier ¶
type DetailsCarrier interface { // Details returns details on the error, if applicable. Details() map[string]interface{} }
DetailsCarrier can be implemented by an error to support error contexts.
type EmailComponent ¶
type GRPCClientComponent ¶
type GRPCClientComponent interface { WithPrefix(prefix string) WithAddress(address string) GetAddress() string GetLogger() appctx.Logger Dial(options ...grpc.DialOption) *grpc.ClientConn DialContext(ctx context.Context, options ...grpc.DialOption) *grpc.ClientConn }
type GRPCServerComponent ¶
type GRPCServerComponent interface { WithAddress(address string) WithListener(lis net.Listener) WithServerOptions(serverOpts ...grpc.ServerOption) WithServeMuxOptions(muxOpts ...runtime.ServeMuxOption) WithUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) WithStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) GetLogger() appctx.Logger GetServer() *grpc.Server GetGateway() *runtime.ServeMux Start(ctx context.Context) }
type GinComponent ¶
type GormDBComponent ¶
type GroupSubJob ¶
type IDCarrier ¶
type IDCarrier interface { // ID returns application error ID on the error, if applicable. ID() string }
IDCarrier can be implemented by an error to support error contexts.
type Image ¶
type Image struct { ID int `json:"id" gorm:"column:id;" db:"id"` Name string `json:"name" gorm:"column:name;" db:"name"` Path string `json:"path" gorm:"column:path;" db:"path"` URL string `json:"url" gorm:"-" db:"-"` Width int `json:"width" gorm:"column:width;" db:"width"` Height int `json:"height" gorm:"column:height;" db:"height"` Provider string `json:"provider,omitempty" gorm:"column:provider;" db:"provider"` }
type Paging ¶
type PubSubComponent ¶
type ReasonCarrier ¶
type ReasonCarrier interface { // Reason returns the reason for the error, if applicable. Reason() string }
ReasonCarrier can be implemented by an error to support error contexts.
type RedisDBComponent ¶
type RedisDBComponent interface {
GetDB() *redis.Client
}
type RequestIDCarrier ¶
type RequestIDCarrier interface { // RequestID returns the ID of the request that caused the error, if applicable. RequestID() string }
RequestIDCarrier can be implemented by an error to support error contexts.
type Requester ¶
func GetRequester ¶
type SQLModel ¶
type SQLModel struct { ID int `json:"-" gorm:"column:id;" db:"id"` FakeID *util.UID `json:"id,omitempty" gorm:"-"` CreatedAt *time.Time `json:"created_at,omitempty" gorm:"column:created_at;" db:"created_at"` UpdatedAt *time.Time `json:"updated_at,omitempty" gorm:"column:updated_at;" db:"updated_at"` }
func NewSQLModel ¶
func NewSQLModel() SQLModel
type SimpleUser ¶
type SimpleUser struct { SQLModel FirstName string `json:"first_name" gorm:"column:first_name;" db:"first_name"` LastName string `json:"last_name" gorm:"column:last_name;" db:"last_name"` Avatar *Image `json:"avatar" gorm:"column:avatar;" db:"avatar"` }
func NewSimpleUser ¶
func NewSimpleUser(id int, firstName, lastName string, avatar *Image) SimpleUser
func (SimpleUser) TableName ¶
func (SimpleUser) TableName() string
type StatusCarrier ¶
type StatusCarrier interface { // ID returns the error id, if applicable. Status() string }
StatusCarrier can be implemented by an error to support error contexts.
type StatusCodeCarrier ¶
type StatusCodeCarrier interface { // StatusCode returns the status code of this error. StatusCode() int }
StatusCodeCarrier can be implemented by an error to support setting status codes in the error itself.
type StorageComponent ¶
type StorageComponent interface { UploadFile(ctx context.Context, data []byte, key string, contentType string) (url string, storageName string, err error) GetPresignedURL(ctx context.Context, key string, expiration time.Duration) (string, error) GetPresignedURLs(ctx context.Context, keys []string, expiration time.Duration) (map[string]string, error) DeleteFiles(ctx context.Context, keys []string) error }
Click to show internal directories.
Click to hide internal directories.