Documentation ¶
Overview ¶
Package "glock" provides the core glock functionality, such as performing locks and unlocks.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUnknown = &GlockError{Code: 0, Message: "An unexpected error occurred. Please check the logs."} // Returned when a key is not provided. ErrMissingKey = &GlockError{Code: 1, Message: "Missing required param: 'key'"} // Returned when a secret is not provided. ErrMissingSecret = &GlockError{Code: 2, Message: "Missing required param: 'secret'"} // Returned when an invalid duration is provided. ErrInvalidDuration = &GlockError{Code: 3, Message: "Invalid 'duration' provided."} // Returned when attempting to place a lock on a key that is already locked. ErrLockExists = &GlockError{Code: 4, Message: "Key already locked."} // Returned when attempting to perform an action on a key that is not locked. ErrLockNotExists = &GlockError{Code: 5, Message: "Key is not locked."} // Returned when attempting to use a secret that doesn't match the locked key's secret. ErrSecretDoesNotMatch = &GlockError{Code: 6, Message: "Secret does not match."} // Returned when a duration is not provided. ErrMissingDuration = &GlockError{Code: 7, Message: "Missing required param: 'duration'"} )
Functions ¶
Types ¶
type GlockError ¶
func (GlockError) String ¶
func (e GlockError) String() string
type Glocker ¶
type Glocker interface { // Lock attempts to register a lock on the specified key and return a secret value that // can later be used to unlock. Lock(key string) (string, *GlockError) // LockWithDuration is the same as Lock, however it automatically expires the key after // a specified duration. LockWithDuration(key string, durationMs int) (string, *GlockError) // Unlock attempts to unlock a locked key using the secret provided. // If the secret doesn't match, or the key isn't locked, an error is returned. Unlock(key, secret string) *GlockError // Extend attempts to extend the lock on a key. // If the key was locked without an expire time, the extension will be the current time + durationMs. // If the key isn't locked or the secret doesn't match, an error is returned. Extend(key, secret string, durationMs int) *GlockError }
The Glocker interface defines the functionality of a 'glock'. The interface allows for multiple implementations, such as a mock 'glock'.
Click to show internal directories.
Click to hide internal directories.