mirror of
https://github.com/restic/restic.git
synced 2025-12-03 22:21:47 +00:00
backend: let ParseConfig return a Config pointer
In order to change the backend initialization in `global.go` to be able
to generically call cfg.ApplyEnvironment() for supported backends, the
`interface{}` returned by `ParseConfig` must contain a pointer to the
configuration.
An alternative would be to use reflection to convert the type from
`interface{}(Config)` to `interface{}(*Config)` (from value to pointer
type). However, this would just complicate the type mess further.
This commit is contained in:
@@ -35,9 +35,9 @@ func init() {
|
||||
|
||||
// ParseConfig parses the string s and extracts the gcs config. The
|
||||
// supported configuration format is gs:bucketName:/[prefix].
|
||||
func ParseConfig(s string) (Config, error) {
|
||||
func ParseConfig(s string) (*Config, error) {
|
||||
if !strings.HasPrefix(s, "gs:") {
|
||||
return Config{}, errors.New("gs: invalid format")
|
||||
return nil, errors.New("gs: invalid format")
|
||||
}
|
||||
|
||||
// strip prefix "gs:"
|
||||
@@ -47,7 +47,7 @@ func ParseConfig(s string) (Config, error) {
|
||||
// remainder as prefix
|
||||
bucket, prefix, colon := strings.Cut(s, ":")
|
||||
if !colon {
|
||||
return Config{}, errors.New("gs: invalid format: bucket name or path not found")
|
||||
return nil, errors.New("gs: invalid format: bucket name or path not found")
|
||||
}
|
||||
|
||||
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
|
||||
@@ -55,7 +55,7 @@ func ParseConfig(s string) (Config, error) {
|
||||
cfg := NewConfig()
|
||||
cfg.Bucket = bucket
|
||||
cfg.Prefix = prefix
|
||||
return cfg, nil
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// ApplyEnvironment saves values from the environment to the config.
|
||||
|
||||
@@ -26,10 +26,10 @@ func newGSTestSuite(t testing.TB) *test.Suite[gs.Config] {
|
||||
MinimalData: true,
|
||||
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (gs.Config, error) {
|
||||
NewConfig: func() (*gs.Config, error) {
|
||||
cfg, err := gs.ParseConfig(os.Getenv("RESTIC_TEST_GS_REPOSITORY"))
|
||||
if err != nil {
|
||||
return gs.Config{}, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg.ProjectID = os.Getenv("RESTIC_TEST_GS_PROJECT_ID")
|
||||
|
||||
Reference in New Issue
Block a user