Documentation
¶
Index ¶
- Constants
- func MimeTypeByExtension(ext string) string
- func RedirectURL(endpoint string, key string, options VariantOptions) string
- func ServeDisk(routePath string, dir string) http.Handler
- func URL(endpoint, p string) string
- func WithGcsACL(ctx context.Context, entity gstorage.ACLEntity, role gstorage.ACLRole) context.Context
- func WithGcsAllUsersRead(ctx context.Context) context.Context
- func WithS3ContentType(ctx context.Context, contentType string) context.Context
- func WithS3Private(ctx context.Context) context.Context
- func WithS3PublicRead(ctx context.Context) context.Context
- type NewVariantFunc
- type NullService
- func (NullService) Copy(ctx context.Context, src string, dst string) error
- func (NullService) Delete(ctx context.Context, key string) error
- func (NullService) DeleteBatch(ctx context.Context, keys []string) error
- func (NullService) DeletePrefixed(ctx context.Context, prefix string) error
- func (NullService) Download(ctx context.Context, key string) (io.ReadCloser, error)
- func (NullService) Exist(ctx context.Context, key string) (bool, error)
- func (NullService) SignURL(ctx context.Context, key string, method string, expiresIn time.Duration) (string, http.Header, error)
- func (NullService) URL(key string) string
- func (NullService) Upload(ctx context.Context, key string, reader io.Reader) error
- type S3Options
- type Server
- type ServerOption
- type ServerOptions
- type Service
- func NewDiskService(dir string, endpoint string) (Service, error)
- func NewGCSService(bucket string, endpoint string) (Service, error)
- func NewGCSServiceWithClient(bucket string, endpoint string, client *gstorage.Client) Service
- func NewNullService() Service
- func NewS3(cfg aws.Config, bucket string, endpoint string, options ...S3Options) (Service, error)
- type Storage
- type Transformer
- type URLOption
- type URLOptions
- type URLSigner
- type Variant
- type VariantFactory
- type VariantOptions
- func (o VariantOptions) Format() string
- func (o VariantOptions) Get(key string) any
- func (o VariantOptions) Quality() int
- func (o VariantOptions) ResizeToFill() ([2]int, bool)
- func (o VariantOptions) Set(key string, value any) VariantOptions
- func (o VariantOptions) SetFormat(format string) VariantOptions
- func (o VariantOptions) SetQuality(quality int) VariantOptions
- func (o VariantOptions) SetResizeToFill(size [2]int) VariantOptions
- func (o VariantOptions) SetSize(size int) VariantOptions
- func (o VariantOptions) Size() int
- func (o VariantOptions) URLQuery() map[string]string
Constants ¶
const ( CtxS3ACL contextKey = "s3_acl" CtxS3ContentType contextKey = "s3_contentType" )
const (
Ctx_GCS_ACL contextKey = "gcs_acl"
)
Variables ¶
This section is empty.
Functions ¶
func MimeTypeByExtension ¶
func RedirectURL ¶
func RedirectURL(endpoint string, key string, options VariantOptions) string
RedirectURL returns serving URL of the variant. Deprecated: out of date.
func WithGcsACL ¶
func WithS3ContentType ¶
WithS3ContentType set s3 object content-type for upload and copy.
func WithS3Private ¶
WithS3Private set s3 object acl to private for upload and copy.
Types ¶
type NewVariantFunc ¶
type NewVariantFunc func(service Service, originKey string, options VariantOptions) Variant
func (NewVariantFunc) NewVariant ¶
func (f NewVariantFunc) NewVariant(service Service, originPath string, options VariantOptions) Variant
type NullService ¶
type NullService struct{}
func (NullService) DeleteBatch ¶
func (NullService) DeleteBatch(ctx context.Context, keys []string) error
func (NullService) DeletePrefixed ¶
func (NullService) DeletePrefixed(ctx context.Context, prefix string) error
func (NullService) Download ¶
func (NullService) Download(ctx context.Context, key string) (io.ReadCloser, error)
func (NullService) URL ¶
func (NullService) URL(key string) string
type S3Options ¶
type S3Options struct { // config upload or copy ACL. Default is private ACL *types.ObjectCannedACL }
type Server ¶
type ServerOption ¶ added in v0.3.0
type ServerOption func(o *ServerOptions)
type ServerOptions ¶ added in v0.3.0
type ServerOptions struct { KeyEncoder func(key string) string KeyDecoder func(encodedKey string) string // URLResolver is used to resolve the URL of the variant or origin file. // Default will use Service.URL(key) method URLResolver func(key string) string // Will sign serving URL to prevent somebody to change serving URL SigningKey []byte // Expire duration for signed serving URL SigningExpires time.Duration }
type Service ¶
type Service interface { Upload(ctx context.Context, key string, reader io.Reader) error Download(ctx context.Context, key string) (io.ReadCloser, error) Copy(ctx context.Context, src string, dst string) error Delete(ctx context.Context, key string) error DeleteBatch(ctx context.Context, keys []string) error DeletePrefixed(ctx context.Context, prefix string) error Exist(ctx context.Context, key string) (bool, error) URL(key string) string // SignURL returns a signed URL for the given key. // // method must be one of "GET", "PUT", "HEAD", "DELETE". SignURL(ctx context.Context, key string, method string, expiresIn time.Duration) (string, http.Header, error) }
func NewDiskService ¶
NewDiskService creates a new disk service. dir is the directory to store the files.
func NewGCSServiceWithClient ¶
func NewNullService ¶
func NewNullService() Service
type Storage ¶
type Storage interface { // TODO: Service Service() Service Variant(key string, options VariantOptions) Variant }
func New ¶
func New(service Service, variantFactory VariantFactory) Storage
New creates a new storage. If variantFactory is nil, NewVariantFactory(NewTransformer()) will be used.
type Transformer ¶
type Transformer interface {
Transform(ctx context.Context, options VariantOptions, format string, source io.Reader, writer io.Writer) error
}
func NewTransformer ¶
func NewTransformer() Transformer
type URLOption ¶ added in v0.5.0
type URLOption func(o *URLOptions)
func WithURLExpires ¶ added in v0.5.0
WithURLExpires sets the expires of the serving URL. 0 means never expires.
func (URLOption) Apply ¶ added in v0.5.0
func (o URLOption) Apply(options *URLOptions)
type URLOptions ¶ added in v0.5.0
type URLOptions struct {
// contains filtered or unexported fields
}
type URLSigner ¶ added in v0.4.0
type URLSigner interface { // exp will be ignored if exp is 0. Sign(url string, exp time.Duration) (string, error) // return error if invalid Validate(signedUrl string) error }
func NewHmacURLSigner ¶ added in v0.4.0
type Variant ¶
func NewVariant ¶
func NewVariant(service Service, originKey string, options VariantOptions, transformer Transformer) Variant
type VariantFactory ¶
type VariantFactory interface {
NewVariant(service Service, originPath string, options VariantOptions) Variant
}
func NewVariantFactory ¶
func NewVariantFactory(transformer Transformer) VariantFactory
type VariantOptions ¶
func ParseVariantOptions ¶
func ParseVariantOptions(query url.Values) (VariantOptions, error)
func (VariantOptions) Format ¶
func (o VariantOptions) Format() string
func (VariantOptions) Get ¶ added in v0.4.0
func (o VariantOptions) Get(key string) any
func (VariantOptions) Quality ¶
func (o VariantOptions) Quality() int
func (VariantOptions) ResizeToFill ¶
func (o VariantOptions) ResizeToFill() ([2]int, bool)
func (VariantOptions) Set ¶ added in v0.4.0
func (o VariantOptions) Set(key string, value any) VariantOptions
func (VariantOptions) SetFormat ¶
func (o VariantOptions) SetFormat(format string) VariantOptions
SetFormat sets the format of the variant. Must be one of "jpg", "png".
func (VariantOptions) SetQuality ¶
func (o VariantOptions) SetQuality(quality int) VariantOptions
SetQuality sets the quality of the variant. Must be between 1 and 100. Default is 80.
func (VariantOptions) SetResizeToFill ¶
func (o VariantOptions) SetResizeToFill(size [2]int) VariantOptions
SetResizeToFill sets the with and height of the variant. Cut the image to a rectangle from the center and resize it to the given size.
func (VariantOptions) SetSize ¶
func (o VariantOptions) SetSize(size int) VariantOptions
SetSize sets the size of the variant. Cut the image to a square from the center and resize it to the given size.
func (VariantOptions) Size ¶
func (o VariantOptions) Size() int
func (VariantOptions) URLQuery ¶
func (o VariantOptions) URLQuery() map[string]string