backend, options: Prefer strings.Cut to SplitN

Also realigned the various "split into host🪣prefix"
implementations.
This commit is contained in:
greatroar
2022-11-27 18:09:59 +01:00
committed by Michael Eischer
parent 60aa87bbab
commit 65612d797c
9 changed files with 56 additions and 66 deletions

View File

@@ -43,14 +43,13 @@ func ParseConfig(s string) (interface{}, error) {
// use the first entry of the path as the bucket name and the
// remainder as prefix
data := strings.SplitN(s, ":", 2)
if len(data) < 2 {
container, prefix, colon := strings.Cut(s, ":")
if !colon {
return nil, errors.New("azure: invalid format: bucket name or path not found")
}
container, path := data[0], path.Clean(data[1])
path = strings.TrimPrefix(path, "/")
prefix = strings.TrimPrefix(path.Clean(prefix), "/")
cfg := NewConfig()
cfg.Container = container
cfg.Prefix = path
cfg.Prefix = prefix
return cfg, nil
}