Move store initialization to store package
This will allow importing storage.Config without importing every SQL drivers in the known universe
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
package storage
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrSQLStorageRequiresFile = errors.New("sql storage requires a non-empty file to be defined")
|
||||
)
|
||||
|
||||
// Config is the configuration for storage
|
||||
type Config struct {
|
||||
// File is the path of the file to use for persistence
|
||||
@ -12,3 +18,11 @@ type Config struct {
|
||||
// If blank, uses the default in-memory store
|
||||
Type Type `yaml:"type"`
|
||||
}
|
||||
|
||||
// ValidateAndSetDefaults validates the configuration and sets the default values (if applicable)
|
||||
func (c *Config) ValidateAndSetDefaults() error {
|
||||
if (c.Type == TypePostgres || c.Type == TypeSQLite) && len(c.File) == 0 {
|
||||
return ErrSQLStorageRequiresFile
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user