diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2022-04-06 00:02:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-06 00:02:19 -0700 |
| commit | 49ecb8d11c9d11d67583356bdd8896a7f97252a3 (patch) | |
| tree | 086d0469178ddd4d68657fab1c0b480ca42c5a28 | |
| parent | 7c85cb332d6aa207350b81fad8d03823a29baab4 (diff) | |
| parent | d02f13c2d189684911ffafe352a77a4b90a64045 (diff) | |
| download | seaweedfs-49ecb8d11c9d11d67583356bdd8896a7f97252a3.tar.xz seaweedfs-49ecb8d11c9d11d67583356bdd8896a7f97252a3.zip | |
Merge pull request #2879 from leyou240/master
remove Redundant type conversion and use strings.TrimSuffix to enhance readability
| -rw-r--r-- | weed/remote_storage/remote_storage.go | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/weed/remote_storage/remote_storage.go b/weed/remote_storage/remote_storage.go index d8d1e1f5c..e4a027199 100644 --- a/weed/remote_storage/remote_storage.go +++ b/weed/remote_storage/remote_storage.go @@ -12,11 +12,11 @@ import ( "time" ) +const slash = "/" + func ParseLocationName(remote string) (locationName string) { - if strings.HasSuffix(string(remote), "/") { - remote = remote[:len(remote)-1] - } - parts := strings.SplitN(string(remote), "/", 2) + remote = strings.TrimSuffix(remote, slash) + parts := strings.SplitN(remote, slash, 2) if len(parts) >= 1 { return parts[0] } @@ -25,35 +25,31 @@ func ParseLocationName(remote string) (locationName string) { func parseBucketLocation(remote string) (loc *remote_pb.RemoteStorageLocation) { loc = &remote_pb.RemoteStorageLocation{} - if strings.HasSuffix(string(remote), "/") { - remote = remote[:len(remote)-1] - } - parts := strings.SplitN(string(remote), "/", 3) + remote = strings.TrimSuffix(remote, slash) + parts := strings.SplitN(remote, slash, 3) if len(parts) >= 1 { loc.Name = parts[0] } if len(parts) >= 2 { loc.Bucket = parts[1] } - loc.Path = string(remote[len(loc.Name)+1+len(loc.Bucket):]) + loc.Path = remote[len(loc.Name)+1+len(loc.Bucket):] if loc.Path == "" { - loc.Path = "/" + loc.Path = slash } return } func parseNoBucketLocation(remote string) (loc *remote_pb.RemoteStorageLocation) { loc = &remote_pb.RemoteStorageLocation{} - if strings.HasSuffix(string(remote), "/") { - remote = remote[:len(remote)-1] - } - parts := strings.SplitN(string(remote), "/", 2) + remote = strings.TrimSuffix(remote, slash) + parts := strings.SplitN(remote, slash, 2) if len(parts) >= 1 { loc.Name = parts[0] } - loc.Path = string(remote[len(loc.Name):]) + loc.Path = remote[len(loc.Name):] if loc.Path == "" { - loc.Path = "/" + loc.Path = slash } return } |
