replaced if-else chain with switch

This commit is contained in:
Christian Kemper 2016-02-14 07:01:14 -08:00
parent 535dfaf097
commit 48f85fbb09
1 changed files with 5 additions and 4 deletions

View File

@ -25,12 +25,13 @@ const defaultPrefix = "restic"
func ParseConfig(s string) (interface{}, error) { func ParseConfig(s string) (interface{}, error) {
var path []string var path []string
cfg := Config{} cfg := Config{}
if strings.HasPrefix(s, "s3://") { switch {
case strings.HasPrefix(s, "s3://"):
s = s[5:] s = s[5:]
path = strings.SplitN(s, "/", 3) path = strings.SplitN(s, "/", 3)
cfg.Endpoint = path[0] cfg.Endpoint = path[0]
path = path[1:] path = path[1:]
} else if strings.HasPrefix(s, "s3:http") { case strings.HasPrefix(s, "s3:http"):
s = s[3:] s = s[3:]
// assume that a URL has been specified, parse it and // assume that a URL has been specified, parse it and
// use the host as the endpoint and the path as the // use the host as the endpoint and the path as the
@ -49,12 +50,12 @@ func ParseConfig(s string) (interface{}, error) {
cfg.UseHTTP = true cfg.UseHTTP = true
} }
path = strings.SplitN(url.Path[1:], "/", 2) path = strings.SplitN(url.Path[1:], "/", 2)
} else if strings.HasPrefix(s, "s3:") { case strings.HasPrefix(s, "s3:"):
s = s[3:] s = s[3:]
path = strings.SplitN(s, "/", 3) path = strings.SplitN(s, "/", 3)
cfg.Endpoint = path[0] cfg.Endpoint = path[0]
path = path[1:] path = path[1:]
} else { default:
return nil, errors.New("s3: invalid format") return nil, errors.New("s3: invalid format")
} }
if len(path) < 1 { if len(path) < 1 {