github.com/sandwich-go/boost@v1.3.29/misc/cloud/storage_gcs.go (about) 1 package cloud 2 3 import ( 4 "fmt" 5 "net/url" 6 "strings" 7 ) 8 9 const StorageTypeGCS StorageType = "gcs" // google δΊ‘ 10 11 func init() { 12 register(StorageTypeGCS, newGCStorage) 13 } 14 15 type gcsStorage struct { 16 *baseStorage 17 } 18 19 func newGCStorage(accessKeyID string, secretAccessKey string, bucket string, opts ...StorageOption) (Storage, error) { 20 bb, err := newBaseBucket(accessKeyID, secretAccessKey, bucket, func(options *StorageOptions) (ep string, err error) { 21 return "storage.googleapis.com", nil 22 }, opts...) 23 if err != nil { 24 return nil, err 25 } 26 s := &gcsStorage{baseStorage: bb} 27 s.setObjectNameResolver(func(u *url.URL) (string, error) { 28 return strings.TrimPrefix(u.Path, "/"+s.bucket+"/"), nil 29 }) 30 return s, nil 31 } 32 33 func (c gcsStorage) GetRootUrl() string { 34 return fmt.Sprintf("https://storage.googleapis.com/%s", c.bucket) 35 }