From 48f85fbb09043a413a06ffb655297e33bc72a517 Mon Sep 17 00:00:00 2001 From: Christian Kemper Date: Sun, 14 Feb 2016 07:01:14 -0800 Subject: [PATCH] replaced if-else chain with switch --- backend/s3/config.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/s3/config.go b/backend/s3/config.go index 4dab8a25c..b65c77488 100644 --- a/backend/s3/config.go +++ b/backend/s3/config.go @@ -25,12 +25,13 @@ const defaultPrefix = "restic" func ParseConfig(s string) (interface{}, error) { var path []string cfg := Config{} - if strings.HasPrefix(s, "s3://") { + switch { + case strings.HasPrefix(s, "s3://"): s = s[5:] path = strings.SplitN(s, "/", 3) cfg.Endpoint = path[0] path = path[1:] - } else if strings.HasPrefix(s, "s3:http") { + case strings.HasPrefix(s, "s3:http"): s = s[3:] // assume that a URL has been specified, parse it and // use the host as the endpoint and the path as the @@ -49,12 +50,12 @@ func ParseConfig(s string) (interface{}, error) { cfg.UseHTTP = true } path = strings.SplitN(url.Path[1:], "/", 2) - } else if strings.HasPrefix(s, "s3:") { + case strings.HasPrefix(s, "s3:"): s = s[3:] path = strings.SplitN(s, "/", 3) cfg.Endpoint = path[0] path = path[1:] - } else { + default: return nil, errors.New("s3: invalid format") } if len(path) < 1 {