Documentation ¶
Index ¶
- 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 AdvisoryLockStore
- type LockFactory
- type LockType
- type MetricsCollector
- type SessionFactory
- type StringMap
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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()
ResetAdvisoryLockMetricsCollectors 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 AdvisoryLockStore ¶
type AdvisoryLockStore struct {
// contains filtered or unexported fields
}
AdvisoryLockStore is a thread-safe map that stores AdvisoryLocks. Map access is unsafe only when updates are occurring. As long as all goroutines are only reading—looking up elements in the map, including iterating through it using a for range loop and not changing the map by assigning to elements or doing deletions, it is safe for them to access the map concurrently without synchronization.
func NewAdvisoryLockStore ¶
func NewAdvisoryLockStore() *AdvisoryLockStore
NewAdvisoryLockStore returns a new AdvisoryLockStore.
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 { }
type SessionFactory ¶
type StringMap ¶
similar to gorms datatypes.JSONMap but it restricts the values to strings
func EmptyMapToNilStringMap ¶
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 |