gatus/storage/config.go
TwiN 9287e2f9e2 Move store initialization to store package
This will allow importing storage.Config without importing every SQL drivers in the known universe
2021-10-28 19:35:46 -04:00

29 lines
731 B
Go

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
// If blank, persistence is disabled
//
// XXX: Rename to path for v4.0.0
File string `yaml:"file"`
// Type of store
// 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
}