bucket

package module
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 13 Imported by: 0

README

helix.go - Bucket integration

Website Go API reference Go Report Card GitHub Release

The bucket integration provides an opinionated and standardized way to interact with bucket providers through drivers.

Documentation

Overview

Package bucket exposes an opinionated and standardized way to interact with bucket providers through drivers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket interface {
	Exists(ctx context.Context, key string) bool
	Read(ctx context.Context, key string) ([]byte, error)
	Write(ctx context.Context, key string, value []byte, opts *OptionsWrite) error
	Copy(ctx context.Context, srcKey string, dstKey string) error
	Delete(ctx context.Context, key string) error
}

Bucket exposes an opinionated and standardized way to interact with buckets across different providers through drivers.

func Connect

func Connect(cfg Config) (Bucket, error)

Connect tries to create a Bucket client given the Config. Returns an error if Config is not valid or if the initialization failed.

type Config

type Config struct {

	// Driver sets the driver to use.
	//
	// Required.
	//
	// Example:
	//
	//   bucket.DriverAWS
	Driver Driver `json:"driver"`

	// Bucket is the name of the bucket.
	//
	// Required.
	//
	// Example:
	//
	//   "my-bucket"
	Bucket string `json:"bucket"`

	// Subfolder sets an optional subfolder where all keys are stored in the bucket.
	//
	// Default:
	//
	//   "/"
	//
	// Example:
	//
	//   "my/subfolder/"
	//
	// Operations on "<key>" will be translated to "my/subfolder/<key>".
	Subfolder string `json:"subfolder,omitempty"`
}

Config is used to configure the Bucket integration.

type Driver

type Driver interface {
	// contains filtered or unexported methods
}

Driver allows to set the driver to use for the bucket integration.

var DriverAWS Driver = &driverAWS{}

DriverAWS allows to use AWS S3 as bucket driver. This driver relies on generic environment variables required by the AWS SDK (v2):

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_REGION

Config example:

bucket.Config{
  Driver: bucket.DriverAWS,
  Bucket: "my-bucket",
}
var DriverAzure Driver = &driverAzure{}

DriverAzure allows to use Azure Blob Storage as bucket driver. This driver relies on generic environment variables required by the Azure SDK:

  • AZURE_STORAGE_ACCOUNT
  • AZURE_STORAGE_KEY || AZURE_STORAGE_SAS_TOKEN

Config example:

bucket.Config{
  Driver: bucket.DriverAzure,
  Bucket: "my-container",
}
var DriverGoogleCloud Driver = &driverGoogleCloud{}

DriverGoogleCloud allows to use Google Cloud Storage as bucket driver. This driver relies on generic environment variables required by the Google Cloud SDK:

  • GOOGLE_APPLICATION_CREDENTIALS

Config example:

bucket.Config{
  Driver: bucket.DriverGoogleCloud,
  Bucket: "my-bucket",
}
var DriverLocal Driver = &driverLocal{}

DriverLocal allows to use local files as bucket driver.

Config example:

bucket.Config{
  Driver: bucket.DriverLocal,
  Bucket: "/path/to/folder",
}

type OptionsWrite

type OptionsWrite struct {

	// CacheControl specifies caching attributes that services may use when serving
	// the blob.
	//
	// Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
	CacheControl string `json:"cache_control,omitempty"`

	// ContentDisposition specifies whether the blob content is expected to be
	// displayed inline or as an attachment.
	//
	// Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
	ContentDisposition string `json:"content_disposition,omitempty"`

	// ContentEncoding specifies the encoding used for the blob's content, if any.
	//
	// Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
	ContentEncoding string `json:"content_encoding,omitempty"`

	// ContentLanguage specifies the language used in the blob's content, if any.
	//
	// Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language
	ContentLanguage string `json:"content_language,omitempty"`

	// ContentType specifies the MIME type of the blob being written. If not set,
	// it will be inferred from the content using the algorithm described at
	// https://mimesniff.spec.whatwg.org/.
	//
	// Documentation: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
	ContentType string `json:"content_type,omitempty"`

	// ContentMD5 is used as a message integrity check. If len(ContentMD5) > 0, the
	// MD5 hash of the bytes written must match ContentMD5.
	//
	// Documentation: https://tools.ietf.org/html/rfc1864
	ContentMD5 []byte `json:"content_md5,omitempty"`

	// Metadata holds key/value strings to be associated with the blob, or nil.
	// Keys may not be empty, and are lowercased before being written. Duplicate
	// case-insensitive keys (e.g., "foo" and "FOO") will result in an error.
	Metadata map[string]string `json:"metadata,omitempty"`
}

OptionsWrite is used to set options when writing blob.

Jump to

Keyboard shortcuts

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