Documentation
¶
Overview ¶
Package config provides the Driver interface. All config drivers must implement this interface, register themselves, optionally provide a `WithInstance` function and pass the tests in package config/testing.
Index ¶
Examples ¶
Constants ¶
View Source
const NilVersion int = -1
Variables ¶
View Source
var ( ErrLocked = fmt.Errorf("can't acquire lock") ErrNotLocked = fmt.Errorf("can't unlock, as not currently locked") )
Functions ¶
func CasRestoreOnErr ¶
CasRestoreOnErr CAS wrapper to automatically restore the lock state on error
func GenerateAdvisoryLockId ¶
GenerateAdvisoryLockId inspired by rails migrations, see https://goo.gl/8o9bCT
Types ¶
type Driver ¶
type Driver interface { // Open returns a new driver instance configured with parameters // coming from the URL string. Migrate will call this function // only once per instance. Open(url string) (Driver, error) // Close closes the underlying config instance managed by the driver. // Migrate will call this function only once per instance. Close() error // Lock should acquire a config lock so that only one migration process // can run at a time. Migrate will call this function before Run is called. // If the implementation can't provide this functionality, return nil. // Return config.ErrLocked if config is already locked. Lock() error // Unlock should release the lock. Migrate will call this function after // all migrations have been run. Unlock() error // Run applies a migration to the config. migration is guaranteed to be not nil. Run(migration io.Reader) error // Version returns the currently active version and if the config is dirty. // When no migration has been applied, it must return version -1. // Dirty means, a previous migration failed and user interaction is required. Version() (version int, err error) // Drop deletes everything in the config. // Note that this is a breaking action, a new call to Open() is necessary to // ensure subsequent calls work as expected. Drop() error }
Driver is the interface every config driver must implement.
Example ¶
// see config/stub for an example // config/stub/stub.go has the driver implementation // config/stub/stub_test.go runs config/testing/test.go:Test
Output:
Click to show internal directories.
Click to hide internal directories.