mirror of
https://github.com/restic/restic.git
synced 2025-12-03 21:21:47 +00:00
backend: let ParseConfig return concrete type
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) (interface{}, error) {
|
||||
func ParseConfig(s string) (Config, error) {
|
||||
if !strings.HasPrefix(s, "gs:") {
|
||||
return nil, errors.New("gs: invalid format")
|
||||
return Config{}, errors.New("gs: invalid format")
|
||||
}
|
||||
|
||||
// strip prefix "gs:"
|
||||
@@ -47,7 +47,7 @@ func ParseConfig(s string) (interface{}, error) {
|
||||
// remainder as prefix
|
||||
bucket, prefix, colon := strings.Cut(s, ":")
|
||||
if !colon {
|
||||
return nil, errors.New("gs: invalid format: bucket name or path not found")
|
||||
return Config{}, errors.New("gs: invalid format: bucket name or path not found")
|
||||
}
|
||||
|
||||
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
|
||||
|
||||
@@ -27,12 +27,11 @@ func newGSTestSuite(t testing.TB) *test.Suite {
|
||||
|
||||
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
||||
NewConfig: func() (interface{}, error) {
|
||||
gscfg, err := gs.ParseConfig(os.Getenv("RESTIC_TEST_GS_REPOSITORY"))
|
||||
cfg, err := gs.ParseConfig(os.Getenv("RESTIC_TEST_GS_REPOSITORY"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cfg := gscfg.(gs.Config)
|
||||
cfg.ProjectID = os.Getenv("RESTIC_TEST_GS_PROJECT_ID")
|
||||
cfg.Prefix = fmt.Sprintf("test-%d", time.Now().UnixNano())
|
||||
return cfg, nil
|
||||
|
||||
Reference in New Issue
Block a user