Documentation ¶
Index ¶
- Variables
- func ArgsToOrderBy(orderByArgs []string, disallowedFields map[string]string) (orderBy []string, err *errors.ServiceError)
- func FieldNameWalk(n tsl.Node, disallowedFields map[string]string) (newNode tsl.Node, err *errors.ServiceError)
- func GetTableName(g2 *gorm.DB) string
- func MarkForRollback(ctx context.Context, err error)
- func Migrate(g2 *gorm.DB) error
- func MigrateTo(sessionFactory SessionFactory, migrationID string)
- func NewContext(ctx context.Context, connection SessionFactory) (context.Context, error)
- func RegisterAdvisoryLockMetrics()
- func ResetAdvisoryLockMetricsCollectors()
- func Resolve(ctx context.Context)
- func TransactionMiddleware(next http.Handler, connection SessionFactory) http.Handler
- func UnregisterAdvisoryLockMetrics()
- func UpdateAdvisoryLockCountMetric(lockType LockType, status string)
- func UpdateAdvisoryLockDurationMetric(lockType LockType, status string, startTime time.Time)
- type AdvisoryLock
- type AdvisoryLockFactory
- func (f *AdvisoryLockFactory) NewAdvisoryLock(ctx context.Context, id string, lockType LockType) (string, error)
- func (f *AdvisoryLockFactory) NewNonBlockingLock(ctx context.Context, id string, lockType LockType) (string, bool, error)
- func (f *AdvisoryLockFactory) Unlock(ctx context.Context, uuid string)
- type LockFactory
- type LockType
- type MetricsCollector
- type SessionFactory
Constants ¶
This section is empty.
Variables ¶
var MetricsLabels = []string{
metricsTypeLabel,
metricsStatusLabel,
}
MetricsLabels - Array of labels added to metrics:
var MetricsNames = []string{
countMetric,
durationMetric,
}
MetricsNames - Array of Names of the metrics:
Functions ¶
func ArgsToOrderBy ¶
func ArgsToOrderBy( orderByArgs []string, disallowedFields map[string]string) (orderBy []string, err *errors.ServiceError)
ArgsToOrderBy returns cleaned orderBy list.
func FieldNameWalk ¶
func FieldNameWalk( n tsl.Node, disallowedFields map[string]string) (newNode tsl.Node, err *errors.ServiceError)
FieldNameWalk walks on the filter tree and check/replace the search fields names: a. the the field name is valid. b. replace the field name with the SQL column name.
func GetTableName ¶
func MarkForRollback ¶
MarkForRollback flags the transaction stored in the context for rollback and logs whatever error caused the rollback
func MigrateTo ¶
func MigrateTo(sessionFactory SessionFactory, migrationID string)
MigrateTo a specific migration will not seed the database, seeds are up to date with the latest schema based on the most recent migration This should be for testing purposes mainly
func NewContext ¶
NewContext returns a new context with transaction stored in it. Upon error, the original context is still returned along with an error
func ResetAdvisoryLockMetricsCollectors ¶
func ResetAdvisoryLockMetricsCollectors()
ResetMetricCollectors resets all collectors
func TransactionMiddleware ¶
func TransactionMiddleware(next http.Handler, connection SessionFactory) http.Handler
TransactionMiddleware creates a new HTTP middleware that begins a database transaction and stores it in the request context.
Types ¶
type AdvisoryLock ¶
type AdvisoryLock struct {
// contains filtered or unexported fields
}
AdvisoryLock represents a postgres advisory lock
begin # start a Tx select pg_advisory_xact_lock(id, lockType) # obtain the lock (blocking) end # end the Tx and release the lock
UUID is a way to own the lock. Only the very first service call that owns the lock will have the correct UUID. This is necessary to allow functions to call other service functions as part of the same lock (id, lockType).
type AdvisoryLockFactory ¶
type AdvisoryLockFactory struct {
// contains filtered or unexported fields
}
func NewAdvisoryLockFactory ¶
func NewAdvisoryLockFactory(connection SessionFactory) *AdvisoryLockFactory
NewAdvisoryLockFactory returns a new factory with AdvisoryLock stored in it.
func (*AdvisoryLockFactory) NewAdvisoryLock ¶
func (*AdvisoryLockFactory) NewNonBlockingLock ¶
type LockFactory ¶
type LockFactory interface { // NewAdvisoryLock constructs a new AdvisoryLock that is a blocking PostgreSQL advisory lock // defined by (id, lockType) and returns a UUID as this AdvisoryLock owner id. NewAdvisoryLock(ctx context.Context, id string, lockType LockType) (string, error) // NewNonBlockingLock constructs a new nonblocking AdvisoryLock defined by (id, lockType), // returns a UUID and a boolean on whether the lock is acquired. NewNonBlockingLock(ctx context.Context, id string, lockType LockType) (string, bool, error) // Unlock unlocks one AdvisoryLock by its owner id. Unlock(ctx context.Context, uuid string) }
LockFactory provides the blocking/unblocking locks based on PostgreSQL advisory lock.
type MetricsCollector ¶
type MetricsCollector interface { }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package db_context dbContext provides a wrapper around db context handling to allow access to the db context without requiring importing the db package, thus avoiding cyclic imports
|
Package db_context dbContext provides a wrapper around db context handling to allow access to the db context without requiring importing the db package, thus avoiding cyclic imports |