2020-08-06 20:58:47 +03:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2023-04-22 16:37:07 +03:00
|
|
|
"context"
|
2020-08-06 20:58:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// Store saves and loads config.
|
|
|
|
type Store interface {
|
|
|
|
// Save writes config to the store.
|
2023-04-22 16:37:07 +03:00
|
|
|
Save(ctx context.Context, cfg *Config) error
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
// Load reads config from the store.
|
2023-05-01 06:59:34 +03:00
|
|
|
Load(ctx context.Context) (*Config, error)
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
// Location returns the location of the store, typically
|
|
|
|
// a file path.
|
|
|
|
Location() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiscardStore implements Store but its Save method is no-op
|
|
|
|
// and Load always returns a new empty Config. Useful for testing.
|
2022-12-18 11:35:59 +03:00
|
|
|
type DiscardStore struct{}
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
var _ Store = (*DiscardStore)(nil)
|
|
|
|
|
|
|
|
// Load returns a new empty Config.
|
2023-05-01 06:59:34 +03:00
|
|
|
func (DiscardStore) Load(context.Context) (*Config, error) {
|
2020-08-06 20:58:47 +03:00
|
|
|
return New(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save is no-op.
|
2023-04-22 16:37:07 +03:00
|
|
|
func (DiscardStore) Save(context.Context, *Config) error {
|
2020-08-06 20:58:47 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-12-18 09:07:38 +03:00
|
|
|
// Location returns /dev/null.
|
2020-08-06 20:58:47 +03:00
|
|
|
func (DiscardStore) Location() string {
|
|
|
|
return "/dev/null"
|
|
|
|
}
|