b2

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExpiredToken is returned by the client when authorization token
	// has expired. If returned, repeating the same request will acquire
	// a new authorization token.
	ErrExpiredToken = errors.New("expired auth token")
)

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	AccountID      string                `json:"accountId"`
	ID             string                `json:"bucketId"`
	Info           map[string]string     `json:"bucketInfo"`
	Name           string                `json:"bucketName"`
	Type           string                `json:"bucketType"`
	LifecycleRules []BucketLifecycleRule `json:"lifecycleRules"`
	Revision       int                   `json:"revision"`
}

Bucket is used to represent a B2 Bucket

type BucketCorsRule

type BucketCorsRule struct {
	Name              string   `json:"corsRuleName"`
	AllowedOrigins    []string `json:"allowedOrigins"`
	AllowedHeaders    []string `json:"allowedHeaders"`
	AllowedOperations []string `json:"allowedOperations"`
	ExposeHeaders     []string `json:"exposeHeaders"`
	MaxAgeSeconds     int      `json:"maxAgeSeconds"`
}

BucketCorsRule is used to represent a Bucket's CORS rule

See more on https://www.backblaze.com/b2/docs/cors_rules.html

type BucketCreateRequest

type BucketCreateRequest struct {
	AccountID      string                `json:"accountId"`
	Name           string                `json:"bucketName"`
	Type           string                `json:"bucketType"`
	Info           map[string]string     `json:"bucketInfo,omitempty"`
	CorsRules      []BucketCorsRule      `json:"corsRules,omitempty"`
	LifecycleRules []BucketLifecycleRule `json:"lifecycleRules,omitempty"`
}

BucketCreateRequest represents a request to create a Bucket

type BucketLifecycleRule

type BucketLifecycleRule struct {
	DaysFromHidingToDeleting  int    `json:"daysFromHidingToDeleting"`
	DaysFromUploadingToHiding int    `json:"daysFromUploadingToHiding"`
	FileNamePrefix            string `json:"fileNamePrefix"`
}

BucketLifecycleRule tells B2 to automatically hide and/or delete old files

See more on https://www.backblaze.com/b2/docs/lifecycle_rules.html

type BucketListRequest

type BucketListRequest struct {
	AccountID string `json:"accountId"`
	BucketID  string `json:"bucketId,omitempty"`
	Name      string `json:"bucketName,omitempty"`
	Types     string `json:"bucketTypes,omitempty"`
}

BucketListRequest represents a request to list Buckets

type BucketService

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

BucketService handles communication with the Bucket related methods of the B2 API

func (*BucketService) Create

func (s *BucketService) Create(ctx context.Context, createRequest *BucketCreateRequest) (*Bucket, *http.Response, error)

Create a new Bucket

func (*BucketService) List

func (s *BucketService) List(ctx context.Context, listRequest *BucketListRequest) ([]Bucket, *http.Response, error)

List all Buckets

type Cache added in v0.4.0

type Cache interface {
	Get(key string) (interface{}, error)
	Set(key string, value interface{}) error
}

Cache defines the interface for interacting with a cache

type Client

type Client struct {

	// The account identifier
	AccountID string

	// The base URL for downloading files
	DownloadURL *url.URL

	// Services used for communicating with the API
	Bucket *BucketService
	File   *FileService
	// contains filtered or unexported fields
}

Client manages communication with Backblaze API

func NewClient

func NewClient(keyId, keySecret string, opts ...ClientOpt) (*Client, error)

NewClient returns a new Backblaze API client

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response

The API response is JSON decoded and stored in the value pointed to by v. If v implements the io.Writer interface, the raw response will be written to v, without attempting to decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body interface{}) (*http.Request, error)

NewRequest creates an API request suitable for use with Client.Do

The path should always be specified without a preceding slash. It will be resolved to the BaseURL of the Client.

If specified, the value pointed to by body is JSON encoded and included in as the request body.

type ClientOpt

type ClientOpt func(*Client) error

ClientOpt are options for New

func SetBaseURL

func SetBaseURL(bu string) ClientOpt

SetBaseURL is a client option for setting the base URL

func SetCache added in v0.4.0

func SetCache(cache Cache) ClientOpt

SetCache is a client option for changing cache client

type DiskCache added in v0.4.0

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

DiskCache implements the Cache interface

func NewDiskCache added in v0.4.0

func NewDiskCache(path string) (*DiskCache, error)

NewDiskCache returns a new disk based cache

It is the caller's responsibility to make sure that the path exists and is writeable

func (*DiskCache) Get added in v0.4.0

func (c *DiskCache) Get(key string) (interface{}, error)

Get returns the value from cache

func (*DiskCache) Set added in v0.4.0

func (c *DiskCache) Set(key string, value interface{}) error

Set stores value in cache

type File added in v0.3.0

type File struct {
	AccountID       string            `json:"accountId"`
	Action          string            `json:"action"`
	BucketID        string            `json:"bucketId"`
	ContentLength   int               `json:"contentLength"`
	ContentSha1     string            `json:"contentSha1"`
	ContentType     string            `json:"contentType"`
	FileID          string            `json:"fileId"`
	FileInfo        map[string]string `json:"fileInfo"`
	FileName        string            `json:"fileName"`
	UploadTimestamp int64             `json:"uploadTimestamp"`
}

File describes a File or a Folder in a Bucket

type FileListRequest added in v0.3.0

type FileListRequest struct {
	BucketID      string `json:"bucketId"`
	StartFileName string `json:"startFileName,omitempty"`
	MaxFileCount  int    `json:"maxFileCount,omitempty"`
	Prefix        string `json:"prefix,omitempty"`
	Delimiter     string `json:"delimiter,omitempty"`
}

FileListRequest represents a request to list files in a Bucket

type FileService added in v0.3.0

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

FileService handles communication with the File related methods of the B2 API

func (*FileService) Download added in v0.3.0

func (s *FileService) Download(ctx context.Context, url string, w io.Writer) (*http.Response, error)

Download a file

func (*FileService) List added in v0.3.0

func (s *FileService) List(ctx context.Context, listRequest *FileListRequest) ([]File, *http.Response, error)

List files in a Bucket

func (*FileService) Upload added in v0.5.0

func (s *FileService) Upload(ctx context.Context, uploadAuthorization *UploadAuthorization, src, dst string) (*File, *http.Response, error)

Upload a file

func (*FileService) UploadAuthorization added in v0.5.0

func (s *FileService) UploadAuthorization(ctx context.Context, uploadAuthorizationRequest *UploadAuthorizationRequest) (*UploadAuthorization, *http.Response, error)

UploadAuthorization returns the information for uploading a file

type InMemoryCache added in v0.4.0

type InMemoryCache struct {
}

InMemoryCache implements the Cache interface

func NewInMemoryCache added in v0.4.0

func NewInMemoryCache() (*InMemoryCache, error)

NewInMemoryCache returns a new in-memory cache

func (*InMemoryCache) Get added in v0.4.0

func (c *InMemoryCache) Get(key string) (interface{}, error)

Get returns the value from cache

func (*InMemoryCache) Set added in v0.4.0

func (c *InMemoryCache) Set(key string, value interface{}) error

Set stores value in cache

type UploadAuthorization added in v0.5.0

type UploadAuthorization struct {
	BucketID  string `json:"bucketId"`
	UploadURL string `json:"uploadUrl"`
	Token     string `json:"authorizationToken"`
}

UploadAuthorization contains the information for uploading a file

type UploadAuthorizationRequest added in v0.5.0

type UploadAuthorizationRequest struct {
	BucketID string `json:"bucketId"`
}

UploadAuthorizationRequest represents a request to obtain a URL for uploading files

Jump to

Keyboard shortcuts

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