Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorHandlingGormConfigurer() fx.Annotated
- func NewGorm(di gormInitDI) *gorm.DB
- type DataError
- func NewConstraintViolationError(value interface{}, causes ...interface{}) DataError
- func NewDataError(code int64, e interface{}, causes ...interface{}) DataError
- func NewDuplicateKeyError(value interface{}, causes ...interface{}) DataError
- func NewErrorWithStatusCode(err error, sc int) DataError
- func NewInternalError(value interface{}, causes ...interface{}) DataError
- func NewRecordNotFoundError(value interface{}, causes ...interface{}) DataError
- type DataProperties
- type DbCreator
- type DbHealthIndicator
- type DefaultGormErrorTranslator
- type ErrorTranslator
- type GormConfigurer
- type GormErrorTranslator
- type GormLogger
- func (l GormLogger) Error(ctx context.Context, s string, i ...interface{})
- func (l GormLogger) Info(ctx context.Context, s string, i ...interface{})
- func (l GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
- func (l GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (string, int64), err error)
- func (l GormLogger) Warn(ctx context.Context, s string, i ...interface{})
- type LoggingProperties
- type TransactionProperties
- type WebDataErrorTranslator
Constants ¶
const ( ErrorTranslatorOrderGorm // gorm error -> data error ErrorTranslatorOrderData // data error -> data error with status code )
const ( ErrorTypeCodeInternal = Reserved + iota<<ErrorTypeOffset ErrorTypeCodeNonTransient ErrorTypeCodeTransient ErrorTypeCodeUncategorizedServerSide )
All "Type" values are used as mask
const ( ErrorSubTypeCodeQuery = ErrorTypeCodeNonTransient + iota<<ErrorSubTypeOffset ErrorSubTypeCodeApi ErrorSubTypeCodeDataRetrieval ErrorSubTypeCodeDataIntegrity ErrorSubTypeCodeTransaction ErrorSubTypeCodeSecurity )
All "SubType" values are used as mask sub types of ErrorTypeCodeNonTransient
const ( ErrorSubTypeCodeConcurrency = ErrorTypeCodeTransient + iota<<ErrorSubTypeOffset ErrorSubTypeCodeTimeout ErrorSubTypeCodeReplica )
All "SubType" values are used as mask sub types of ErrorTypeCodeTransient
const ( ErrorCodeInvalidSQL = ErrorSubTypeCodeQuery + iota ErrorCodeInvalidPagination )
ErrorSubTypeCodeQuery
const ( ErrorCodeInvalidApiUsage = ErrorSubTypeCodeApi + iota ErrorCodeUnsupportedCondition ErrorCodeUnsupportedOptions ErrorCodeInvalidCrudModel ErrorCodeInvalidCrudParam )
ErrorSubTypeCodeApi
const ( ErrorCodeRecordNotFound = ErrorSubTypeCodeDataRetrieval + iota ErrorCodeOrmMapping ErrorCodeIncorrectRecordCount )
ErrorSubTypeCodeDataRetrieval
const ( ErrorCodeDuplicateKey = ErrorSubTypeCodeDataIntegrity + iota ErrorCodeConstraintViolation ErrorCodeInvalidSchema )
ErrorSubTypeCodeDataIntegrity
const ( ErrorCodeAuthenticationFailed = ErrorSubTypeCodeSecurity + iota ErrorCodeFieldOperationDenied )
ErrorSubTypeCodeSecurity
const ( ErrorCodePessimisticLocking = ErrorSubTypeCodeConcurrency + iota ErrorCodeOptimisticLocking )
ErrorSubTypeCodeConcurrency
const ( GormCallbackBeforeCreate = "gorm:before_create" GormCallbackAfterCreate = "gorm:after_create" GormCallbackBeforeQuery = "gorm:query" GormCallbackAfterQuery = "gorm:after_query" GormCallbackBeforeUpdate = "gorm:before_update" GormCallbackAfterUpdate = "gorm:after_update" GormCallbackBeforeDelete = "gorm:before_delete" GormCallbackAfterDelete = "gorm:after_delete" GormCallbackBeforeRow = "gorm:row" GormCallbackAfterRow = "gorm:row" GormCallbackBeforeRaw = "gorm:raw" GormCallbackAfterRaw = "gorm:raw" )
const (
ErrorCodeInternal = ErrorSubTypeCodeInternal + iota
)
ErrorSubTypeCodeInternal
const (
ErrorCodeInvalidTransaction = ErrorSubTypeCodeTransaction + iota
)
ErrorSubTypeCodeTransaction
const (
ErrorCodeQueryTimeout = ErrorSubTypeCodeTimeout + iota
)
ErrorSubTypeCodeTimeout
const (
)ErrorSubTypeCodeApi
const (
ErrorSubTypeCodeInternal = ErrorTypeCodeInternal + iota<<ErrorSubTypeOffset
)
All "SubType" values are used as mask sub types of ErrorTypeCodeInternal
const (
GormConfigurerGroup = "gorm_config"
)
const (
ManagementPropertiesPrefix = "data"
)
const (
// Reserved data reserved reserved error range
Reserved = 0xdb << ReservedOffset
)
Variables ¶
var ( ErrorCategoryData = NewErrorCategory(Reserved, errors.New("error type: data")) ErrorTypeInternal = NewErrorType(ErrorTypeCodeInternal, errors.New("error type: internal")) ErrorTypeNonTransient = NewErrorType(ErrorTypeCodeNonTransient, errors.New("error type: non-transient")) ErrorTypeTransient = NewErrorType(ErrorTypeCodeTransient, errors.New("error type: transient")) ErrorTypeUnCategorizedServerSide = NewErrorType(ErrorTypeCodeUncategorizedServerSide, errors.New("error type: uncategorized server-side")) ErrorSubTypeInternalError = NewErrorSubType(ErrorSubTypeCodeInternal, errors.New("error sub-type: internal")) ErrorSubTypeQuery = NewErrorSubType(ErrorSubTypeCodeQuery, errors.New("error sub-type: query")) ErrorSubTypeApi = NewErrorSubType(ErrorSubTypeCodeApi, errors.New("error sub-type: api")) ErrorSubTypeDataRetrieval = NewErrorSubType(ErrorSubTypeCodeDataRetrieval, errors.New("error sub-type: retrieval")) ErrorSubTypeDataIntegrity = NewErrorSubType(ErrorSubTypeCodeDataIntegrity, errors.New("error sub-type: integrity")) ErrorSubTypeTransaction = NewErrorSubType(ErrorSubTypeCodeTransaction, errors.New("error sub-type: transaction")) ErrorSubTypeSecurity = NewErrorSubType(ErrorSubTypeCodeSecurity, errors.New("error sub-type: security")) ErrorSubTypeConcurrency = NewErrorSubType(ErrorSubTypeCodeConcurrency, errors.New("error sub-type: concurency")) ErrorSubTypeTimeout = NewErrorSubType(ErrorSubTypeCodeTimeout, errors.New("error sub-type: timeout")) ErrorSubTypeReplica = NewErrorSubType(ErrorSubTypeCodeReplica, errors.New("error sub-type: replica")) )
ErrorTypes, can be used in errors.Is
var ( ErrorSortByUnknownColumn = NewDataError(ErrorCodeOrmMapping, "SortBy column unknown") ErrorRecordNotFound = NewDataError(ErrorCodeRecordNotFound, gorm.ErrRecordNotFound) ErrorIncorrectRecordCount = NewDataError(ErrorCodeIncorrectRecordCount, "incorrect record count") ErrorDuplicateKey = NewDataError(ErrorCodeDuplicateKey, "duplicate key") )
Concrete error, can be used in errors.Is for exact match
var ( GormErrorMapping = map[error]DataError{ gorm.ErrRecordNotFound: NewDataError(ErrorCodeRecordNotFound, gorm.ErrRecordNotFound), gorm.ErrInvalidTransaction: NewDataError(ErrorCodeInvalidTransaction, gorm.ErrInvalidTransaction), gorm.ErrNotImplemented: NewDataError(ErrorCodeInvalidApiUsage, gorm.ErrNotImplemented), gorm.ErrMissingWhereClause: NewDataError(ErrorCodeInvalidSQL, gorm.ErrMissingWhereClause), gorm.ErrUnsupportedRelation: NewDataError(ErrorCodeInvalidSchema, gorm.ErrUnsupportedRelation), gorm.ErrPrimaryKeyRequired: NewDataError(ErrorCodeInvalidSQL, gorm.ErrPrimaryKeyRequired), gorm.ErrModelValueRequired: NewDataError(ErrorCodeOrmMapping, gorm.ErrModelValueRequired), gorm.ErrInvalidData: NewDataError(ErrorCodeOrmMapping, gorm.ErrInvalidData), gorm.ErrUnsupportedDriver: NewDataError(ErrorCodeInternal, gorm.ErrUnsupportedDriver), gorm.ErrRegistered: NewDataError(ErrorCodeInternal, gorm.ErrRegistered), gorm.ErrInvalidField: NewDataError(ErrorCodeInvalidSQL, gorm.ErrInvalidField), gorm.ErrEmptySlice: NewDataError(ErrorCodeIncorrectRecordCount, gorm.ErrEmptySlice), gorm.ErrDryRunModeUnsupported: NewDataError(ErrorCodeInvalidApiUsage, gorm.ErrDryRunModeUnsupported), gorm.ErrInvalidDB: NewDataError(ErrorCodeInvalidApiUsage, gorm.ErrInvalidDB), gorm.ErrInvalidValue: NewDataError(ErrorCodeInvalidSQL, gorm.ErrInvalidValue), gorm.ErrInvalidValueOfLength: NewDataError(ErrorCodeInvalidSQL, gorm.ErrInvalidValueOfLength), } )
var Module = &bootstrap.Module{ Name: "DB", Precedence: bootstrap.DatabasePrecedence, Options: []fx.Option{ fx.Provide(BindDataProperties), fx.Invoke(registerHealth), }, }
Functions ¶
Types ¶
type DataError ¶
type DataError interface { error NestedError Details() interface{} WithDetails(interface{}) DataError WithMessage(msg string, args ...interface{}) DataError }
func NewConstraintViolationError ¶
func NewConstraintViolationError(value interface{}, causes ...interface{}) DataError
func NewDataError ¶
func NewDuplicateKeyError ¶
func NewDuplicateKeyError(value interface{}, causes ...interface{}) DataError
func NewErrorWithStatusCode ¶
func NewInternalError ¶
func NewInternalError(value interface{}, causes ...interface{}) DataError
func NewRecordNotFoundError ¶
func NewRecordNotFoundError(value interface{}, causes ...interface{}) DataError
type DataProperties ¶
type DataProperties struct { Logging LoggingProperties `json:"logging"` Transaction TransactionProperties `json:"transaction"` }
func BindDataProperties ¶
func BindDataProperties(ctx *bootstrap.ApplicationContext) DataProperties
BindDataProperties create and bind SessionProperties, with a optional prefix
func NewDataProperties ¶
func NewDataProperties() *DataProperties
NewDataProperties create a DataProperties with default values
type DbHealthIndicator ¶
type DbHealthIndicator struct {
// contains filtered or unexported fields
}
DbHealthIndicator Note: we currently only support one database
func (*DbHealthIndicator) Name ¶
func (i *DbHealthIndicator) Name() string
type DefaultGormErrorTranslator ¶
type DefaultGormErrorTranslator struct {
ErrorTranslator
}
func (DefaultGormErrorTranslator) TranslateWithDB ¶
func (t DefaultGormErrorTranslator) TranslateWithDB(db *gorm.DB) error
type ErrorTranslator ¶
ErrorTranslator redefines web.ErrorTranslator and order.Ordered having this redefinition is to break dependency between data and web package
func NewGormErrorTranslator ¶
func NewGormErrorTranslator() ErrorTranslator
func NewWebDataErrorTranslator ¶
func NewWebDataErrorTranslator() ErrorTranslator
type GormConfigurer ¶
type GormErrorTranslator ¶
type GormLogger ¶
type GormLogger struct {
// contains filtered or unexported fields
}
func (GormLogger) Error ¶
func (l GormLogger) Error(ctx context.Context, s string, i ...interface{})
func (GormLogger) LogMode ¶
func (l GormLogger) LogMode(level gormlogger.LogLevel) gormlogger.Interface
type LoggingProperties ¶
type LoggingProperties struct { Level log.LoggingLevel `json:"level"` SlowThreshold utils.Duration `json:"slow-threshold"` }
type TransactionProperties ¶
type TransactionProperties struct {
MaxRetry int `json:"max-retry"`
}
type WebDataErrorTranslator ¶
type WebDataErrorTranslator struct{}
WebDataErrorTranslator implements web.ErrorTranslator
func (WebDataErrorTranslator) Order ¶
func (WebDataErrorTranslator) Order() int