github.com/sandwich-go/boost@v1.3.29/misc/cloud/storage_s3.go (about) 1 package cloud 2 3 import "fmt" 4 5 const StorageTypeS3 StorageType = "s3" // aws s3 6 7 func init() { 8 register(StorageTypeS3, newS3Storage) 9 } 10 11 type s3Storage struct { 12 *baseStorage 13 } 14 15 func newS3Storage(accessKeyID string, secretAccessKey string, bucket string, opts ...StorageOption) (Storage, error) { 16 bb, err := newBaseBucket(accessKeyID, secretAccessKey, bucket, func(options *StorageOptions) (ep string, err error) { 17 if len(options.GetRegion()) == 0 { 18 err = ErrRegionShouldNotEmptyForS3 19 } else { 20 ep = fmt.Sprintf("s3.dualstack.%s.amazonaws.com", options.GetRegion()) 21 } 22 return 23 }, opts...) 24 if err != nil { 25 return nil, err 26 } 27 return &s3Storage{baseStorage: bb}, nil 28 } 29 30 func (c s3Storage) GetRootUrl() string { 31 return fmt.Sprintf("https://%s.s3.amazonaws.com", c.bucket) 32 }