2021-02-03 05:06:34 +01:00
|
|
|
package storage
|
|
|
|
|
2021-10-29 01:35:46 +02:00
|
|
|
import "errors"
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrSQLStorageRequiresFile = errors.New("sql storage requires a non-empty file to be defined")
|
|
|
|
)
|
|
|
|
|
2021-07-16 04:07:30 +02:00
|
|
|
// Config is the configuration for storage
|
2021-02-03 05:06:34 +01:00
|
|
|
type Config struct {
|
2021-02-21 01:00:54 +01:00
|
|
|
// File is the path of the file to use for persistence
|
2021-07-16 04:07:30 +02:00
|
|
|
// If blank, persistence is disabled
|
2021-09-11 00:00:04 +02:00
|
|
|
//
|
|
|
|
// XXX: Rename to path for v4.0.0
|
2021-02-03 05:06:34 +01:00
|
|
|
File string `yaml:"file"`
|
2021-07-16 04:07:30 +02:00
|
|
|
|
|
|
|
// Type of store
|
|
|
|
// If blank, uses the default in-memory store
|
|
|
|
Type Type `yaml:"type"`
|
2021-02-03 05:06:34 +01:00
|
|
|
}
|
2021-10-29 01:35:46 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|