Browse Source

Use strings.CutPrefix for cleaner ARN prefix stripping

Replace strings.HasPrefix checks with strings.CutPrefix for more
idiomatic Go code. This function is available in Go 1.20+ and
provides cleaner conditional logic with the combined check and
extraction.

Addresses review feedback from Gemini Code Assist.
pull/7409/head
Chris Lu 1 month ago
parent
commit
4e4c2ee97e
  1. 8
      weed/s3api/s3api_bucket_policy_handlers.go

8
weed/s3api/s3api_bucket_policy_handlers.go

@ -293,10 +293,10 @@ func (s3a *S3ApiServer) validateResourceForBucket(resource, bucket string) bool
const seaweedPrefix = "arn:seaweed:s3:::"
// Strip the optional ARN prefix to get the resource path
if strings.HasPrefix(resource, awsPrefix) {
resourcePath = resource[len(awsPrefix):]
} else if strings.HasPrefix(resource, seaweedPrefix) {
resourcePath = resource[len(seaweedPrefix):]
if path, ok := strings.CutPrefix(resource, awsPrefix); ok {
resourcePath = path
} else if path, ok := strings.CutPrefix(resource, seaweedPrefix); ok {
resourcePath = path
} else {
resourcePath = resource
}

Loading…
Cancel
Save