gcs

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gcs provides the Google Cloud Storage disk implementation.

Index

Constants

View Source
const (
	// DefaultURLTemplate is the default URL template to use for (*Disk).GetURL().
	DefaultURLTemplate = "https://storage.googleapis.com/{{ .Bucket }}/{{ .Path }}"
)
View Source
const (
	// Provider is the provider name for Google Cloud Storage.
	Provider = "gcs"
)

Variables

This section is empty.

Functions

func NewAutoWire added in v0.3.0

func NewAutoWire(ctx context.Context, cfg map[string]interface{}) (godrive.Disk, error)

NewAutoWire creates a new Google Cloud Storage disk from an autowire configuration.

func Register added in v0.3.0

func Register(cfg *godrive.AutoWireConfig)

Register registeres Google Cloud Storage as a provider for the disk autowire.

Types

type Config

type Config struct {
	Bucket      string
	Public      bool
	URLTemplate string
}

Config is the disk configuration.

type Disk

type Disk struct {
	Client *gcs.Client
	Config Config
}

Disk is the Google Cloud Storage disk.

func NewDisk

func NewDisk(client *gcs.Client, bucket string, options ...Option) *Disk

NewDisk creates a new Google Cloud Storage disk.

func (*Disk) Delete

func (d *Disk) Delete(ctx context.Context, path string) error

Delete deletes the file at the given path.

func (*Disk) Get

func (d *Disk) Get(ctx context.Context, path string) ([]byte, error)

Get retrieves the file at the given path.

func (*Disk) GetURL

func (d *Disk) GetURL(_ context.Context, path string) (string, error)

GetURL returns the public URL for the file at the given path.

func (*Disk) Put

func (d *Disk) Put(ctx context.Context, path string, b []byte) error

Put writes b to the file at the given path.

func (*Disk) PutReader added in v0.5.0

func (d *Disk) PutReader(ctx context.Context, path string, r io.Reader) error

PutReader writes r to the file at the given path.

type InvalidConfigValueError added in v0.3.0

type InvalidConfigValueError struct {
	Key     string
	Details string
}

InvalidConfigValueError means the autowire configuration has an invalid config value.

func (InvalidConfigValueError) Error added in v0.3.0

func (err InvalidConfigValueError) Error() string

type Option

type Option func(*Config)

Option is a disk configuration option.

func Public

func Public(public bool) Option

Public configures the disk to make all uploaded files publicly accessible. Note that this option will not work and storing files will return an error if "uniform bucket-level access" is configured on the bucket, because individual ACL for specific objects is not available for those buckets.

func URLTemplate added in v0.4.1

func URLTemplate(tpl string) Option

URLTemplate overrides the default template for public URLs.

Jump to

Keyboard shortcuts

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