Skip to content

Commit

Permalink
Do errors more informative
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaptoss committed Aug 2, 2024
1 parent 203415e commit cd9af4b
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions internal/storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (s *Storage) bucketAndKey(link *url.URL) (bucket, key string, err error) {
return s3URL.Bucket, s3URL.Key, nil
// should be never happened
default:
return "", "", errors.New("invalid backend")
return "", "", fmt.Errorf("unknown backend: %s", s.backend)
}
}

Expand Down Expand Up @@ -133,27 +133,11 @@ func (s *Storage) GeneratePutURL(fileName, contentType string, contentLength int
}

func (s *Storage) GenerateGetURL(link *url.URL) (signedURL string, err error) {
var bucket, key string

switch s.backend {
case digitalOceanBackend:
spacesURL, err := ParseDOSpacesURL(link)
if err != nil {
return "", fmt.Errorf("failed to parse url [%s]: %w", link, err)
}
key = spacesURL.Key
bucket = spacesURL.Bucket
case awsBackend:
s3URL := s3util.ParseAmazonS3URL(nil, link)
if s3URL.Region != s.region {
return "", ErrRegionMismatched
}
key = s3URL.Key
bucket = s3URL.Bucket
// should be never happened
default:
return "", errors.New("invalid backend")
bucket, key, err := s.bucketAndKey(link)
if err != nil {
return "", fmt.Errorf("failed to get bucket and key: %w", err)
}

req, _ := s.client.GetObjectRequest(&s3.GetObjectInput{
Bucket: &bucket,
Key: &key,
Expand Down

0 comments on commit cd9af4b

Please sign in to comment.