ent

package
v0.0.0-...-286a084 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2016 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func IsBucketNotFound(err error) bool

IsBucketNotFound returns a boolean indicating the error is ErrBucketNotFound.

func IsClient

func IsClient(err error) bool

IsClient returns a boolean indicating if the error is ErrClient.

func IsEmptyBucket

func IsEmptyBucket(err error) bool

IsEmptyBucket returns a boolean indicating if the error is ErrEmptyBucket.

func IsEmptyKey

func IsEmptyKey(err error) bool

IsEmptyKey returns a boolean indicating if the error is ErrEmptyKey.

func IsEmptySource

func IsEmptySource(err error) bool

IsEmptySource returns a boolean indicating if the error is ErrEmptySource

func IsFileNotFound

func IsFileNotFound(err error) bool

IsFileNotFound returns a boolean indicating the error is ErrFileNotFound.

Types

type Bucket

type Bucket struct {
	Name  string `json:"name"`
	Owner Owner  `json:"owner"`
}

A Bucket carries configuration for namespaces like ownership and restrictions.

func NewBucket

func NewBucket(name string, owner Owner) *Bucket

NewBucket returns a new Bucket given a name and an Owner.

type Client

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

Client provides an interface to interact with Ent over HTTP.

func New

func New(addr string, client *http.Client) *Client

New returns a new Client instance given an address and an http.Client, http.DefaultClient is used if client is not passed.

func (*Client) Create

func (c *Client) Create(
	bucket, key string,
	src io.Reader,
) (*ResponseFile, error)

Create stores or replaces the blob under key with the content of src.

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.

func (*Error) Error

func (e *Error) Error() string

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

func NewMemoryFile(key string, data []byte) File

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.

func NewMemoryFS

func NewMemoryFS() FileSystem

NewMemoryFS returns an instance of MemoryFS.

type Files

type Files []File

Files represents group of file

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

func (fs *MemoryFS) Create(
	bucket *Bucket,
	key string,
	src io.Reader,
) (File, error)

Create given a Bucket and a key stores the content of src into a MemoryFile.

func (*MemoryFS) Delete

func (fs *MemoryFS) Delete(bucket *Bucket, key string) error

Delete removes the File stored in the given Bucket under key.

func (*MemoryFS) List

func (fs *MemoryFS) List(
	bucket *Bucket,
	prefix string,
	limit uint64,
	sort SortStrategy,
) (Files, error)

List returns a list of Files matching the given criteria.

func (*MemoryFS) Open

func (fs *MemoryFS) Open(bucket *Bucket, key string) (File, error)

Open returns the File stored under the key.

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) Hash

func (f *MemoryFile) Hash() ([]byte, error)

Hash returns the

func (*MemoryFile) Key

func (f *MemoryFile) Key() string

Key returns the name of the file.

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.

func (*MemoryFile) Seek

func (f *MemoryFile) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read or Write on File.

func (*MemoryFile) Write

func (f *MemoryFile) Write(b []byte) (int, error)

Write writes len(b) bytes to 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 Owner

type Owner struct {
	Email mail.Address `json:"email"`
}

An Owner represents the identity of a person or group.

type Provider

type Provider interface {
	Get(name string) (*Bucket, error)
	List() ([]*Bucket, error)
}

A Provider implements access to a collection of Buckets.

func NewMemoryProvider

func NewMemoryProvider(buckets ...*Bucket) Provider

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

type ResponseFile struct {
	Key          string
	LastModified time.Time
	Bucket       *Bucket
}

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

type SortStrategy interface {
	EncodeParam() string
	Sort(file Files)
}

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.

Jump to

Keyboard shortcuts

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