gcstorage

package
v0.0.0-...-4cce589 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gcstorage is an implementation of filestorage for Google Cloud

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Creator

type Creator struct {
	// contains filtered or unexported fields
}

Creator creates new filestorage

func NewCreator

func NewCreator(apiKey string, defaultBucket string) (*Creator, error)

NewCreator returns a filestorage creator that will use the provided key to create a new google storage client that will be reused for every new gcstorage instance

func NewCreatorWithContext

func NewCreatorWithContext(ctx context.Context, apiKey string, defaultBucket string) (*Creator, error)

NewCreatorWithContext returns a filestorage creator that will use the provided context and key to create a new google storage client that will be reused for every new gcstorage instance The provided context will be used as default context for all new FileStorage instance

func (*Creator) New

func (c *Creator) New() (filestorage.FileStorage, error)

New returns a new le client

func (*Creator) NewWithContext

func (c *Creator) NewWithContext(ctx context.Context) (filestorage.FileStorage, error)

NewWithContext returns a new gc storage client using the provided context as default context instead of the one provided during the creation of the Creator

type GCStorage

type GCStorage struct {
	// contains filtered or unexported fields
}

GCStorage is an implementation of the FileStorage interface for Google Cloud

func New

func New(apiKey string) (*GCStorage, error)

New returns a new GCStorage instance using a new Google Cloud Storage client

func NewWithClient

func NewWithClient(defaultContext context.Context, client *storage.Client) *GCStorage

NewWithClient returns a new instance of a Google Cloud Storage using the provided client

func NewWithContext

func NewWithContext(ctx context.Context, apiKey string) (*GCStorage, error)

NewWithContext returns a new GCStorage instance using a new Google Cloud Storage client attached to the provided context

func (*GCStorage) Attributes

func (s *GCStorage) Attributes(filepath string) (*filestorage.FileAttributes, error)

Attributes returns the attributes of the file Will use the defaut context

func (*GCStorage) AttributesCtx

func (s *GCStorage) AttributesCtx(ctx context.Context, filepath string) (*filestorage.FileAttributes, error)

AttributesCtx returns the attributes of the file

func (*GCStorage) Delete

func (s *GCStorage) Delete(filepath string) error

Delete removes a file, ignores files that do not exist Will use the defaut context

func (*GCStorage) DeleteCtx

func (s *GCStorage) DeleteCtx(ctx context.Context, filepath string) error

DeleteCtx removes a file, ignores files that do not exist

func (*GCStorage) Exists

func (s *GCStorage) Exists(filepath string) (bool, error)

Exists check if a file exists Will use the defaut context

func (*GCStorage) ExistsCtx

func (s *GCStorage) ExistsCtx(ctx context.Context, filepath string) (bool, error)

ExistsCtx check if a file exists

func (*GCStorage) ID

func (s *GCStorage) ID() string

ID returns the unique identifier of the storage provider

func (*GCStorage) Read

func (s *GCStorage) Read(filepath string) (io.ReadCloser, error)

Read fetches a file a returns a reader Will use the defaut context

func (*GCStorage) ReadCtx

func (s *GCStorage) ReadCtx(ctx context.Context, filepath string) (io.ReadCloser, error)

ReadCtx fetches a file a returns a reader

func (*GCStorage) SetAttributes

func (s *GCStorage) SetAttributes(filepath string, attrs *filestorage.UpdatableFileAttributes) (*filestorage.FileAttributes, error)

SetAttributes sets the attributes of the file Will use the defaut context

func (*GCStorage) SetAttributesCtx

func (s *GCStorage) SetAttributesCtx(ctx context.Context, filepath string, attrs *filestorage.UpdatableFileAttributes) (*filestorage.FileAttributes, error)

SetAttributesCtx sets the attributes of the file

func (*GCStorage) SetBucket

func (s *GCStorage) SetBucket(name string) error

SetBucket is used to set the bucket Always return nil

func (*GCStorage) URL

func (s *GCStorage) URL(filepath string) (string, error)

URL returns the URL of the file Will use the defaut context

func (*GCStorage) URLCtx

func (s *GCStorage) URLCtx(ctx context.Context, filepath string) (string, error)

URLCtx returns the URL of the file

func (*GCStorage) Write

func (s *GCStorage) Write(src io.Reader, destPath string) error

Write copy the provided os.File to dest Will use the defaut context

func (*GCStorage) WriteCtx

func (s *GCStorage) WriteCtx(ctx context.Context, src io.Reader, destPath string) error

WriteCtx copy the provided os.File to dest

func (*GCStorage) WriteIfNotExist

func (s *GCStorage) WriteIfNotExist(src io.Reader, destPath string) (new bool, url string, err error)

WriteIfNotExist copies the provided io.Reader to dest if the file does not already exist Returns:

  • A boolean specifying if the file got uploaded (true) or if already existed (false).
  • A URL to the uploaded file
  • An error if something went wrong

Will use the defaut context

func (*GCStorage) WriteIfNotExistCtx

func (s *GCStorage) WriteIfNotExistCtx(ctx context.Context, src io.Reader, destPath string) (new bool, url string, err error)

WriteIfNotExistCtx copies the provided io.Reader to dest if the file does not already exist Returns:

  • A boolean specifying if the file got uploaded (true) or if already existed (false).
  • A URL to the uploaded file
  • An error if something went wrong

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL