Documentation
¶
Index ¶
- Variables
- type Bucket
- type BucketCorsRule
- type BucketCreateRequest
- type BucketLifecycleRule
- type BucketListRequest
- type BucketService
- type Cache
- type Client
- type ClientOpt
- type DiskCache
- type File
- type FileListRequest
- type FileService
- func (s *FileService) Download(ctx context.Context, url string, w io.Writer) (*http.Response, error)
- func (s *FileService) List(ctx context.Context, listRequest *FileListRequest) ([]File, *http.Response, error)
- func (s *FileService) Upload(ctx context.Context, uploadAuthorization *UploadAuthorization, src, dst string) (*File, *http.Response, error)
- func (s *FileService) UploadAuthorization(ctx context.Context, uploadAuthorizationRequest *UploadAuthorizationRequest) (*UploadAuthorization, *http.Response, error)
- type InMemoryCache
- type UploadAuthorization
- type UploadAuthorizationRequest
Constants ¶
This section is empty.
Variables ¶
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 (*Client) Do ¶
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 ¶
ClientOpt are options for New
func SetBaseURL ¶
SetBaseURL is a client option for setting the base URL
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
NewDiskCache returns a new disk based cache
It is the caller's responsibility to make sure that the path exists and is writeable
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