gcs

package module
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: Apache-2.0 Imports: 21 Imported by: 1

README

Build Status Integration Tests License

go-services-gcs

Google Cloud Storage service support for go-storage.

Install

go get github.com/beyondstorage/go-service-gcs/v2

Usage

import (
	"log"

	_ "github.com/beyondstorage/go-service-gcs/v2"
	"github.com/beyondstorage/go-storage/v4/services"
)

func main() {
	store, err := services.NewStoragerFromString("gcs://bucket_name/path/to/workdir?credential=file:<absolute_path_to_token_file>&project_id=<google_cloud_project_id>")
	if err != nil {
		log.Fatal(err)
	}
	
	// Write data from io.Reader into hello.txt
	n, err := store.Write("hello.txt", r, length)
}

Documentation

Overview

Package gcs provided support for Google Cloud Storage (https://cloud.google.com/storage/)

Code generated by go generate via cmd/definitions; DO NOT EDIT.

Index

Constants

View Source
const (
	StorageClassStandard = "STANDARD"
	StorageClassNearLine = "NEARLINE"
	StorageClassColdLine = "COLDLINE"
	StorageClassArchive  = "ARCHIVE"
)

All available storage classes are listed here.

View Source
const Type = "gcs"

Type is the type for gcs

Variables

This section is empty.

Functions

func New

func New(pairs ...typ.Pair) (typ.Servicer, typ.Storager, error)

New will create both Servicer and Storager.

func NewServicer

func NewServicer(pairs ...typ.Pair) (typ.Servicer, error)

NewServicer will create Servicer only.

func NewStorager

func NewStorager(pairs ...typ.Pair) (typ.Storager, error)

NewStorager will create Storager only.

func WithDefaultServicePairs

func WithDefaultServicePairs(v DefaultServicePairs) Pair

WithDefaultServicePairs will apply default_service_pairs value to Options.

DefaultServicePairs set default pairs for service actions

func WithDefaultStoragePairs

func WithDefaultStoragePairs(v DefaultStoragePairs) Pair

WithDefaultStoragePairs will apply default_storage_pairs value to Options.

DefaultStoragePairs set default pairs for storager actions

func WithEnableVirtualDir added in v2.3.0

func WithEnableVirtualDir() Pair

WithEnableVirtualDir will apply enable_virtual_dir value to Options.

VirtualDir virtual_dir feature is designed for a service that doesn't have native dir support but wants to provide simulated operations.

- If this feature is disabled (the default behavior), the service will behave like it doesn't have any dir support. - If this feature is enabled, the service will support simulated dir behavior in create_dir, create, list, delete, and so on.

This feature was introduced in GSP-109.

func WithEncryptionKey

func WithEncryptionKey(v []byte) Pair

WithEncryptionKey will apply encryption_key value to Options.

EncryptionKey is the customer's 32-byte AES-256 key

func WithKmsKeyName

func WithKmsKeyName(v string) Pair

WithKmsKeyName will apply kms_key_name value to Options.

KmsKeyName is the Cloud KMS key resource. For example, `projects/my-pet-project/locations/us-east1/keyRings/my-key-ring/cryptoKeys/my-key`.

Refer to https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys#add-object-key for more details.

func WithProjectID

func WithProjectID(v string) Pair

WithProjectID will apply project_id value to Options.

ProjectID

func WithServiceFeatures added in v2.1.0

func WithServiceFeatures(v ServiceFeatures) Pair

WithServiceFeatures will apply service_features value to Options.

ServiceFeatures set service features

func WithStorageClass

func WithStorageClass(v string) Pair

WithStorageClass will apply storage_class value to Options.

StorageClass

func WithStorageFeatures added in v2.1.0

func WithStorageFeatures(v StorageFeatures) Pair

WithStorageFeatures will apply storage_features value to Options.

StorageFeatures set storage features

Types

type DefaultServicePairs

type DefaultServicePairs struct {
	Create []Pair
	Delete []Pair
	Get    []Pair
	List   []Pair
}

DefaultServicePairs is default pairs for specific action

type DefaultStoragePairs

type DefaultStoragePairs struct {
	Create    []Pair
	CreateDir []Pair
	Delete    []Pair
	List      []Pair
	Metadata  []Pair
	Read      []Pair
	Stat      []Pair
	Write     []Pair
}

DefaultStoragePairs is default pairs for specific action

type ObjectSystemMetadata added in v2.1.0

type ObjectSystemMetadata struct {
	// EncryptionKeySha256
	EncryptionKeySha256 string
	// StorageClass
	StorageClass string
}

ObjectSystemMetadata stores system metadata for object.

func GetObjectSystemMetadata added in v2.1.0

func GetObjectSystemMetadata(o *Object) ObjectSystemMetadata

GetObjectSystemMetadata will get ObjectSystemMetadata from Object.

- This function should not be called by service implementer. - The returning ObjectServiceMetadata is read only and should not be modified.

type Service

type Service struct {
	typ.UnimplementedServicer
	// contains filtered or unexported fields
}

Service is the gcs config.

func (*Service) Create

func (s *Service) Create(name string, pairs ...Pair) (store Storager, err error)

Create will create a new storager instance.

This function will create a context by default.

func (*Service) CreateWithContext

func (s *Service) CreateWithContext(ctx context.Context, name string, pairs ...Pair) (store Storager, err error)

CreateWithContext will create a new storager instance.

func (*Service) Delete

func (s *Service) Delete(name string, pairs ...Pair) (err error)

Delete will delete a storager instance.

This function will create a context by default.

func (*Service) DeleteWithContext

func (s *Service) DeleteWithContext(ctx context.Context, name string, pairs ...Pair) (err error)

DeleteWithContext will delete a storager instance.

func (*Service) Get

func (s *Service) Get(name string, pairs ...Pair) (store Storager, err error)

Get will get a valid storager instance for service.

This function will create a context by default.

func (*Service) GetWithContext

func (s *Service) GetWithContext(ctx context.Context, name string, pairs ...Pair) (store Storager, err error)

GetWithContext will get a valid storager instance for service.

func (*Service) List

func (s *Service) List(pairs ...Pair) (sti *StoragerIterator, err error)

List will list all storager instances under this service.

This function will create a context by default.

func (*Service) ListWithContext

func (s *Service) ListWithContext(ctx context.Context, pairs ...Pair) (sti *StoragerIterator, err error)

ListWithContext will list all storager instances under this service.

func (*Service) String

func (s *Service) String() string

String implements Servicer.String

type ServiceFeatures added in v2.1.0

type ServiceFeatures struct {
}

type Storage

type Storage struct {
	typ.UnimplementedStorager
	typ.UnimplementedDirer
	// contains filtered or unexported fields
}

Storage is the gcs service client.

func (*Storage) Create

func (s *Storage) Create(path string, pairs ...Pair) (o *Object)

Create will create a new object without any api call.

## Behavior

- Create SHOULD NOT send any API call. - Create SHOULD accept ObjectMode pair as object mode.

This function will create a context by default.

func (*Storage) CreateDir added in v2.1.0

func (s *Storage) CreateDir(path string, pairs ...Pair) (o *Object, err error)

CreateDir will create a new dir object.

This function will create a context by default.

func (*Storage) CreateDirWithContext added in v2.1.0

func (s *Storage) CreateDirWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error)

CreateDirWithContext will create a new dir object.

func (*Storage) Delete

func (s *Storage) Delete(path string, pairs ...Pair) (err error)

Delete will delete an object from service.

## Behavior

- Delete only delete one and only one object.

  • Service DON'T NEED to support remove all.
  • User NEED to implement remove_all by themself.

- Delete is idempotent.

  • Successful delete always return nil error.
  • Delete SHOULD never return `ObjectNotExist`
  • Delete DON'T NEED to check the object exist or not.

This function will create a context by default.

func (*Storage) DeleteWithContext

func (s *Storage) DeleteWithContext(ctx context.Context, path string, pairs ...Pair) (err error)

DeleteWithContext will delete an object from service.

## Behavior

- Delete only delete one and only one object.

  • Service DON'T NEED to support remove all.
  • User NEED to implement remove_all by themself.

- Delete is idempotent.

  • Successful delete always return nil error.
  • Delete SHOULD never return `ObjectNotExist`
  • Delete DON'T NEED to check the object exist or not.

func (*Storage) List

func (s *Storage) List(path string, pairs ...Pair) (oi *ObjectIterator, err error)

List will return list a specific path.

## Behavior

- Service SHOULD support default `ListMode`. - Service SHOULD implement `ListModeDir` without the check for `VirtualDir`. - Service DON'T NEED to `Stat` while in `List`.

This function will create a context by default.

func (*Storage) ListWithContext

func (s *Storage) ListWithContext(ctx context.Context, path string, pairs ...Pair) (oi *ObjectIterator, err error)

ListWithContext will return list a specific path.

## Behavior

- Service SHOULD support default `ListMode`. - Service SHOULD implement `ListModeDir` without the check for `VirtualDir`. - Service DON'T NEED to `Stat` while in `List`.

func (*Storage) Metadata

func (s *Storage) Metadata(pairs ...Pair) (meta *StorageMeta)

Metadata will return current storager metadata.

This function will create a context by default.

func (*Storage) Read

func (s *Storage) Read(path string, w io.Writer, pairs ...Pair) (n int64, err error)

Read will read the file's data.

This function will create a context by default.

func (*Storage) ReadWithContext

func (s *Storage) ReadWithContext(ctx context.Context, path string, w io.Writer, pairs ...Pair) (n int64, err error)

ReadWithContext will read the file's data.

func (*Storage) Stat

func (s *Storage) Stat(path string, pairs ...Pair) (o *Object, err error)

Stat will stat a path to get info of an object.

## Behavior

- Stat SHOULD accept ObjectMode pair as hints.

  • Service COULD have different implementations for different object mode.
  • Service SHOULD check if returning ObjectMode is match

This function will create a context by default.

func (*Storage) StatWithContext

func (s *Storage) StatWithContext(ctx context.Context, path string, pairs ...Pair) (o *Object, err error)

StatWithContext will stat a path to get info of an object.

## Behavior

- Stat SHOULD accept ObjectMode pair as hints.

  • Service COULD have different implementations for different object mode.
  • Service SHOULD check if returning ObjectMode is match

func (*Storage) String

func (s *Storage) String() string

String implements Storager.String

func (*Storage) Write

func (s *Storage) Write(path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error)

Write will write data into a file.

## Behavior

- Write SHOULD NOT return an error as the object exist.

  • Service that has native support for `overwrite` doesn't NEED to check the object exists or not.
  • Service that doesn't have native support for `overwrite` SHOULD check and delete the object if exists.

- A successful write operation SHOULD be complete, which means the object's content and metadata should be the same as specified in write request.

This function will create a context by default.

func (*Storage) WriteWithContext

func (s *Storage) WriteWithContext(ctx context.Context, path string, r io.Reader, size int64, pairs ...Pair) (n int64, err error)

WriteWithContext will write data into a file.

## Behavior

- Write SHOULD NOT return an error as the object exist.

  • Service that has native support for `overwrite` doesn't NEED to check the object exists or not.
  • Service that doesn't have native support for `overwrite` SHOULD check and delete the object if exists.

- A successful write operation SHOULD be complete, which means the object's content and metadata should be the same as specified in write request.

type StorageFeatures added in v2.1.0

type StorageFeatures struct {
	// VirtualDir virtual_dir feature is designed for a service that doesn't have native dir support but wants to provide simulated operations.
	//
	// - If this feature is disabled (the default behavior), the service will behave like it doesn't have any dir support.
	// - If this feature is enabled, the service will support simulated dir behavior in create_dir, create, list, delete, and so on.
	//
	// This feature was introduced in GSP-109.
	VirtualDir bool
}

type StorageSystemMetadata added in v2.1.0

type StorageSystemMetadata struct {
}

StorageSystemMetadata stores system metadata for storage meta.

func GetStorageSystemMetadata added in v2.1.0

func GetStorageSystemMetadata(s *StorageMeta) StorageSystemMetadata

GetStorageSystemMetadata will get SystemMetadata from StorageMeta.

- The returning StorageSystemMetadata is read only and should not be modified.

Jump to

Keyboard shortcuts

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