Documentation
¶
Index ¶
- Constants
- Variables
- func AppendContentType(mimes map[string]bool, extraMimes map[string]string, URL, path string) string
- func LoadExtraMimes() map[string]string
- func LoadMimes() map[string]bool
- func RunTestForAllBackends(t *testing.T, test func(string, Client))
- func SeedBucket(bucket Bucket, seedObjects []SeedObject) error
- type Bucket
- type BucketOptions
- type Client
- type Gcs
- type GcsBucket
- func (b *GcsBucket) AddUser(ctx context.Context, email string) error
- func (b *GcsBucket) CreateObject(ctx context.Context, objectName string, content []byte) error
- func (b *GcsBucket) CreatedAt(ctx context.Context, path string) (time.Time, error)
- func (b *GcsBucket) DeleteDir(ctx context.Context, dir string) error
- func (b *GcsBucket) DeleteFile(ctx context.Context, filename string) error
- func (b *GcsBucket) DeleteObjects(paths []string) error
- func (b *GcsBucket) DeletePath(ctx context.Context, name string) error
- func (b *GcsBucket) Destroy(ctx context.Context) error
- func (b *GcsBucket) IsDir(ctx context.Context, dir string) (bool, error)
- func (b *GcsBucket) IsFile(ctx context.Context, path string) (bool, error)
- func (b *GcsBucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
- func (b *GcsBucket) ListPath(options ListOptions) (PathIterator, error)
- func (b *GcsBucket) RemoveUser(ctx context.Context, email string) error
- func (b *GcsBucket) SetCORS(ctx context.Context) error
- type GcsObjectPager
- type GcsPathIterator
- type InMemoryBucket
- func (b *InMemoryBucket) Add(path string, age time.Time) error
- func (b *InMemoryBucket) CreateObject(ctx context.Context, name string, content []byte) error
- func (b *InMemoryBucket) DeleteDir(ctx context.Context, dir string) error
- func (b *InMemoryBucket) DeleteFile(ctx context.Context, path string) error
- func (b *InMemoryBucket) DeleteObjects(paths []string) error
- func (b *InMemoryBucket) DeletePath(ctx context.Context, path string) error
- func (b *InMemoryBucket) Destroy(ctx context.Context) error
- func (b *InMemoryBucket) IsDir(ctx context.Context, dir string) (bool, error)
- func (b *InMemoryBucket) IsFile(ctx context.Context, path string) (bool, error)
- func (b *InMemoryBucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
- func (b *InMemoryBucket) ListPath(options ListOptions) (PathIterator, error)
- func (b *InMemoryBucket) SetCORS(ctx context.Context) error
- func (b *InMemoryBucket) Size() int
- type InMemoryObjectIterator
- type InMemoryObjectPager
- type InMemoryStorage
- func (c *InMemoryStorage) CreateBucket(ctx context.Context) (string, error)
- func (c *InMemoryStorage) DestroyBucket(ctx context.Context, options BucketOptions) error
- func (c *InMemoryStorage) GetBucket(options BucketOptions) Bucket
- func (c *InMemoryStorage) SignURL(ctx context.Context, options SignURLOptions) (string, error)
- type ListOptions
- type Object
- type ObjectPager
- type PathItem
- type PathIterator
- type S3
- type S3Bucket
- func (b *S3Bucket) CreateObject(ctx context.Context, objectName string, content []byte) error
- func (b *S3Bucket) DeleteDir(ctx context.Context, path string) error
- func (b *S3Bucket) DeleteFile(ctx context.Context, path string) error
- func (b *S3Bucket) DeleteObjects(paths []string) error
- func (b *S3Bucket) DeletePath(ctx context.Context, path string) error
- func (b *S3Bucket) Destroy(ctx context.Context) error
- func (b *S3Bucket) IsDir(ctx context.Context, path string) (bool, error)
- func (b *S3Bucket) IsFile(ctx context.Context, path string) (bool, error)
- func (b *S3Bucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
- func (b *S3Bucket) ListPath(options ListOptions) (PathIterator, error)
- func (b *S3Bucket) SetCORS(ctx context.Context) error
- type S3ObjectPager
- type S3Options
- type S3PathIterator
- type SeedObject
- type ServiceAccountCredentials
- type SignURLOptions
Constants ¶
const GcsStorageListObjectPageSize = 1000 // google cloud API docs' recomendation
const InMemoryStorageObjectPerPage = 100
const SignedURLExpireInMinutes = 20
Variables ¶
var ErrNoMoreObjects = fmt.Errorf("no more objects in the storage")
Functions ¶
func AppendContentType ¶
func LoadExtraMimes ¶
func SeedBucket ¶
func SeedBucket(bucket Bucket, seedObjects []SeedObject) error
Types ¶
type Bucket ¶
type Bucket interface { ListPath(options ListOptions) (PathIterator, error) ListObjectsWithPagination(options ListOptions) (ObjectPager, error) DeleteObjects(paths []string) error CreateObject(ctx context.Context, objectName string, content []byte) error IsDir(ctx context.Context, path string) (bool, error) IsFile(ctx context.Context, path string) (bool, error) DeletePath(ctx context.Context, path string) error DeleteDir(ctx context.Context, path string) error DeleteFile(ctx context.Context, path string) error SetCORS(ctx context.Context) error Destroy(ctx context.Context) error }
type BucketOptions ¶
type Client ¶
type Client interface { GetBucket(options BucketOptions) Bucket CreateBucket(ctx context.Context) (string, error) DestroyBucket(ctx context.Context, options BucketOptions) error SignURL(ctx context.Context, options SignURLOptions) (string, error) }
type Gcs ¶
type Gcs struct { Client *gcsstorage.Client Credentials ServiceAccountCredentials Mimes map[string]bool ExtraMimes map[string]string ManageBucketPermissions bool }
func NewGcsClient ¶
func (*Gcs) DestroyBucket ¶
func (c *Gcs) DestroyBucket(ctx context.Context, options BucketOptions) error
func (*Gcs) GetBucket ¶
func (c *Gcs) GetBucket(options BucketOptions) Bucket
type GcsBucket ¶
type GcsBucket struct { BucketName string BucketHandler *gcsstorage.BucketHandle }
func (*GcsBucket) AddUser ¶
AddUser connects a bucket with a service account with the adequate role permission.
func (*GcsBucket) CreateObject ¶
Only used in tests
func (*GcsBucket) DeleteFile ¶
func (*GcsBucket) DeleteObjects ¶
func (*GcsBucket) DeletePath ¶
DelPath deletes object or directory from a Google Cloud Storage bucket.
func (*GcsBucket) ListObjectsWithPagination ¶
func (b *GcsBucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
func (*GcsBucket) ListPath ¶
func (b *GcsBucket) ListPath(options ListOptions) (PathIterator, error)
func (*GcsBucket) RemoveUser ¶
RemoveUser removes bucket-service account connection.
type GcsObjectPager ¶
type GcsObjectPager struct {
// contains filtered or unexported fields
}
type GcsPathIterator ¶
type GcsPathIterator struct {
// contains filtered or unexported fields
}
func (*GcsPathIterator) Count ¶
func (i *GcsPathIterator) Count() (int, error)
func (*GcsPathIterator) Done ¶
func (i *GcsPathIterator) Done() bool
func (*GcsPathIterator) Next ¶
func (i *GcsPathIterator) Next() (*PathItem, error)
type InMemoryBucket ¶
func (*InMemoryBucket) CreateObject ¶
func (*InMemoryBucket) DeleteDir ¶
func (b *InMemoryBucket) DeleteDir(ctx context.Context, dir string) error
func (*InMemoryBucket) DeleteFile ¶
func (b *InMemoryBucket) DeleteFile(ctx context.Context, path string) error
func (*InMemoryBucket) DeleteObjects ¶
func (b *InMemoryBucket) DeleteObjects(paths []string) error
func (*InMemoryBucket) DeletePath ¶
func (b *InMemoryBucket) DeletePath(ctx context.Context, path string) error
func (*InMemoryBucket) ListObjectsWithPagination ¶
func (b *InMemoryBucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
func (*InMemoryBucket) ListPath ¶
func (b *InMemoryBucket) ListPath(options ListOptions) (PathIterator, error)
func (*InMemoryBucket) Size ¶
func (b *InMemoryBucket) Size() int
type InMemoryObjectIterator ¶
type InMemoryObjectIterator struct {
// contains filtered or unexported fields
}
func (*InMemoryObjectIterator) Count ¶
func (i *InMemoryObjectIterator) Count() (int, error)
func (*InMemoryObjectIterator) Done ¶
func (i *InMemoryObjectIterator) Done() bool
func (*InMemoryObjectIterator) Next ¶
func (i *InMemoryObjectIterator) Next() (*PathItem, error)
type InMemoryObjectPager ¶
type InMemoryObjectPager struct {
// contains filtered or unexported fields
}
func (*InMemoryObjectPager) Count ¶
func (p *InMemoryObjectPager) Count() (int, error)
type InMemoryStorage ¶
type InMemoryStorage struct {
// contains filtered or unexported fields
}
func NewInMemoryStorage ¶
func NewInMemoryStorage() *InMemoryStorage
func (*InMemoryStorage) CreateBucket ¶
func (c *InMemoryStorage) CreateBucket(ctx context.Context) (string, error)
func (*InMemoryStorage) DestroyBucket ¶
func (c *InMemoryStorage) DestroyBucket(ctx context.Context, options BucketOptions) error
func (*InMemoryStorage) GetBucket ¶
func (c *InMemoryStorage) GetBucket(options BucketOptions) Bucket
func (*InMemoryStorage) SignURL ¶
func (c *InMemoryStorage) SignURL(ctx context.Context, options SignURLOptions) (string, error)
type ListOptions ¶
type ListOptions struct { Path string MaxKeys int64 WrapSubDirectories bool PaginationToken string }
func (*ListOptions) UseDelimiter ¶
func (o *ListOptions) UseDelimiter() bool
type ObjectPager ¶
type PathIterator ¶
type S3 ¶
func NewS3Client ¶
func (*S3) CreateBucket ¶
S3 storage uses a single bucket, we don't create anything.
func (*S3) DestroyBucket ¶
func (c *S3) DestroyBucket(ctx context.Context, options BucketOptions) error
We do not delete the bucket, we only empty it
func (*S3) GetBucket ¶
func (c *S3) GetBucket(options BucketOptions) Bucket
S3 storage uses a single bucket, so we ignore the bucket name passed as parameter here.
type S3Bucket ¶
func (*S3Bucket) CreateObject ¶
Only used in tests
func (*S3Bucket) DeleteDir ¶
When deleting a directory, we list all the files in that directory and delete all the listed files in 1000-object chunks using the S3 DeleteObjects operation.
func (*S3Bucket) DeleteObjects ¶
func (*S3Bucket) ListObjectsWithPagination ¶
func (b *S3Bucket) ListObjectsWithPagination(options ListOptions) (ObjectPager, error)
func (*S3Bucket) ListPath ¶
func (b *S3Bucket) ListPath(options ListOptions) (PathIterator, error)
type S3ObjectPager ¶
type S3PathIterator ¶
type S3PathIterator struct { Client *s3.S3 LastOutput *s3.ListObjectsOutput PathPrefix string NextObjectIndex int NextPrefixIndex int IsDone bool }
func (*S3PathIterator) Count ¶
func (i *S3PathIterator) Count() (int, error)
func (*S3PathIterator) Done ¶
func (i *S3PathIterator) Done() bool
func (*S3PathIterator) Next ¶
func (i *S3PathIterator) Next() (*PathItem, error)
type SeedObject ¶
type ServiceAccountCredentials ¶
type ServiceAccountCredentials struct { ProjectID string `json:"project_id"` ClientEmail string `json:"client_email"` PrivateKey string `json:"private_key"` }
ServiceAccountCredentials is an object for parsing the Google Cloud Storage credentials from the JSON file.