Documentation
¶
Index ¶
- Constants
- Variables
- func IsBucketNotFound(err error) bool
- func IsClient(err error) bool
- func IsEmptyBucket(err error) bool
- func IsEmptyKey(err error) bool
- func IsEmptySource(err error) bool
- func IsFileNotFound(err error) bool
- type Bucket
- type Client
- type Error
- type File
- type FileSystem
- type Files
- type ListOptions
- type MemoryFS
- func (fs *MemoryFS) Create(bucket *Bucket, key string, src io.Reader) (File, error)
- func (fs *MemoryFS) Delete(bucket *Bucket, key string) error
- func (fs *MemoryFS) List(bucket *Bucket, prefix string, limit uint64, sort SortStrategy) (Files, error)
- func (fs *MemoryFS) Open(bucket *Bucket, key string) (File, error)
- type MemoryFile
- func (f *MemoryFile) Close() error
- func (f *MemoryFile) Hash() ([]byte, error)
- func (f *MemoryFile) Key() string
- func (f *MemoryFile) LastModified() time.Time
- func (f *MemoryFile) Read(b []byte) (int, error)
- func (f *MemoryFile) Seek(offset int64, whence int) (int64, error)
- func (f *MemoryFile) Write(b []byte) (int, error)
- type MemoryProvider
- type Owner
- type Provider
- type ResponseBucketList
- type ResponseCreated
- type ResponseDeleted
- type ResponseError
- type ResponseFile
- type ResponseFileList
- type SortStrategy
Constants ¶
const ( DefaultLimit uint64 = math.MaxUint64 HeaderETag = "ETag" HeaderLastModified = "Last-Modified" KeyBucket = ":bucket" KeyBlob = ":key" OrderKey = "key" OrderLastModified = "lastModified" OrderAscending = "+" OrderDescending = "-" ParamLimit = "limit" ParamPrefix = "prefix" ParamSort = "sort" RouteBucket = `/{bucket}` RouteFile = `/{bucket}/{key:[a-zA-Z0-9\-_\.~\+\/]+}` )
Constants used in HTTP request/responses.
Variables ¶
var ( ErrBucketNotFound = errors.New("bucket not found") ErrClient = errors.New("ent.Client") ErrEmptyBucket = errors.New("bucket not provided") ErrEmptyKey = errors.New("key not provided") ErrEmptySource = errors.New("source not provided") ErrFileNotFound = errors.New("file not found") ErrInvalidParam = errors.New("invalid param") )
Error codes returned by Ent for missing entities.
Functions ¶
func IsBucketNotFound ¶
IsBucketNotFound returns a boolean indicating the error is ErrBucketNotFound.
func IsEmptyBucket ¶
IsEmptyBucket returns a boolean indicating if the error is ErrEmptyBucket.
func IsEmptyKey ¶
IsEmptyKey returns a boolean indicating if the error is ErrEmptyKey.
func IsEmptySource ¶
IsEmptySource returns a boolean indicating if the error is ErrEmptySource
func IsFileNotFound ¶
IsFileNotFound returns a boolean indicating the error is ErrFileNotFound.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides an interface to interact with Ent over HTTP.
func New ¶
New returns a new Client instance given an address and an http.Client, http.DefaultClient is used if client is not passed.
func (*Client) Get ¶
func (c *Client) Get(bucket, key string) (io.ReadCloser, error)
Get returns the file stored under bucket and key.
func (*Client) List ¶
func (c *Client) List( bucket string, opts *ListOptions, ) ([]ResponseFile, error)
List returns the list of ResponseFiles for a bucket potentially filtered by the provided options.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a wrapper for Ent returned errors.
type File ¶
type File interface { Hash() ([]byte, error) Key() string LastModified() time.Time io.Closer io.Reader io.Seeker io.Writer }
File represents a handle to an open file handle.
func NewMemoryFile ¶
NewMemoryFile returns a MemoryFile.
type FileSystem ¶
type FileSystem interface { Create(bucket *Bucket, key string, data io.Reader) (File, error) Delete(bucket *Bucket, key string) error Open(bucket *Bucket, key string) (File, error) List(bucket *Bucket, prefix string, limit uint64, sort SortStrategy) (Files, error) }
A FileSystem implements CRUD operations for a collection of named files namespaced into buckets.
type ListOptions ¶
type ListOptions struct { Limit uint64 Prefix string Sort SortStrategy }
ListOptions specifies the details of a listing like prefix to filter, amount of files to return.
func (ListOptions) EncodeParams ¶
func (o ListOptions) EncodeParams() string
EncodeParams returns a string that can be used as URL params.
type MemoryFS ¶
type MemoryFS struct {
// contains filtered or unexported fields
}
MemoryFS is an in-memory implementation of FileSystem.
func (*MemoryFS) Create ¶
Create given a Bucket and a key stores the content of src into a MemoryFile.
type MemoryFile ¶
type MemoryFile struct {
// contains filtered or unexported fields
}
MemoryFile is an in-memory implementation of the File interface meant for use in testing scenarios.
func (*MemoryFile) Close ¶
func (f *MemoryFile) Close() error
Close closes the File for further writes.
func (*MemoryFile) LastModified ¶
func (f *MemoryFile) LastModified() time.Time
LastModified returns the time of last modification.
func (*MemoryFile) Read ¶
func (f *MemoryFile) Read(b []byte) (int, error)
Read reads up to len(b) from File.
type MemoryProvider ¶
type MemoryProvider struct {
// contains filtered or unexported fields
}
MemoryProvider is an in-memory Provider implementation.
func (*MemoryProvider) Get ¶
func (p *MemoryProvider) Get(name string) (*Bucket, error)
Get returns the Bucket for the given name.
func (*MemoryProvider) Init ¶
func (p *MemoryProvider) Init() error
Init performs the necessary setup (noop).
func (*MemoryProvider) List ¶
func (p *MemoryProvider) List() ([]*Bucket, error)
List returns all stored Buckets.
type Provider ¶
A Provider implements access to a collection of Buckets.
func NewMemoryProvider ¶
NewMemoryProvider returns a MemoryProvider instance.
type ResponseBucketList ¶
type ResponseBucketList struct { Count int `json:"count"` Duration time.Duration `json:"duration"` Buckets []*Bucket `json:"buckets"` }
ResponseBucketList is used as the intermediate type to craft a response for the retrieval of all buckets.
type ResponseCreated ¶
type ResponseCreated struct { Duration time.Duration `json:"duration"` File ResponseFile `json:"file"` }
ResponseCreated is used as the intermediate type to craft a response for a successful file upload.
type ResponseDeleted ¶
type ResponseDeleted struct { Duration time.Duration `json:"duration"` File ResponseFile `json:"file"` }
ResponseDeleted is used as the intermediate type to craft a response for a successfull file deletion
type ResponseError ¶
type ResponseError struct { Code int `json:"code"` Error string `json:"error"` Description string `json:"description"` }
ResponseError is used as the intermediate type to craft a response for any kind of error condition in the http path. This includes common error cases like an entity could not be found.
type ResponseFile ¶
ResponseFile is used as the intermediate type to craft a response for the retrieval metadata of a File.
func (ResponseFile) MarshalJSON ¶
func (r ResponseFile) MarshalJSON() ([]byte, error)
MarshalJSON returns a ResponseFile JSON encoding with conversion of the files SHA1 to hex.
func (*ResponseFile) UnmarshalJSON ¶
func (r *ResponseFile) UnmarshalJSON(d []byte) error
UnmarshalJSON marshals data into *r with conversion of the hex representation of SHA1 into a []byte.
type ResponseFileList ¶
type ResponseFileList struct { Count int `json:"count"` Duration time.Duration `json:"duration"` Bucket *Bucket `json:"bucket"` Files []ResponseFile `json:"files"` }
ResponseFileList is used as the intermediate type to craft a response for the retrieval of all files in a bucket.
type SortStrategy ¶
SortStrategy implements sorting of Files
func ByKeyStrategy ¶
func ByKeyStrategy(ascending bool) SortStrategy
ByKeyStrategy returns a SortStrategy ordering by key name.
func ByLastModifiedStrategy ¶
func ByLastModifiedStrategy(ascending bool) SortStrategy
ByLastModifiedStrategy returns a SortStrategy ordering by a files modification time.
func NoOpStrategy ¶
func NoOpStrategy() SortStrategy
NoOpStrategy returns a SortStrategy which keeps the order.