Documentation ¶
Index ¶
- Constants
- Variables
- func RandInt(min, max int) int
- func RandStr(length int) string
- type Application
- type ApplicationService
- type ApplicationStorage
- type EncryptionService
- type Error
- type File
- type FileBlob
- type FileBlobStorage
- type FileServeService
- type FileService
- type FileStorage
- type NewApplication
- type NewFile
- type NewTransformation
- type NewUsage
- type TotalUsage
- type TransformService
- type TransformStorage
- type Transformation
- type TransformationOption
- type UpdateApplication
- type UpdateUsage
- type UploadService
- type Usage
- type UsageService
- type UsageStorage
Constants ¶
const ( StorageEngineWasabi = "wasabi" StorageEngineDigitalOcean = "digital_ocean" StorageEngineS3 = "s3" StorageEngineB2 = "b2" StorageEngineAzureBlob = "azure_blob" )
const ( ErrInternal = Error("internal error") ErrInvalidDate = Error("invalid date") ErrNotFound = Error("resource not found") ErrBadRequest = Error("bad request") ErrInvalidJSON = Error("invalid json") )
General errors.
const ( ErrApplicationNotFound = Error("application not found") ErrApplicationNameTaken = Error("application name taken") )
Application errors
const ( ErrBucketNotFound = Error("bucket does not exist") ErrInvalidBucketName = Error("invalid bucket name") ErrInvalidStorageKey = Error("invalid api keys or api keys do not have correct permissions") )
Storage errors
const ( ErrFileNotFound = Error("file not found") ErrFileToLargeToTransform = Error("file is to large to transform") ErrTransformationNotUnique = Error("transformation is not unique") )
File errors
const DateLayout = "2006-01-02"
const DefaultFilePaginationLimit = 25
const (
ErrAuthorizationHeaderMissing = Error("authorization header is missing")
)
const (
ErrUsageNotFound = Error("usage not found")
)
Usage errors
Variables ¶
var ( AvailableStorageEngines = []string{ StorageEngineWasabi, StorageEngineDigitalOcean, StorageEngineS3, StorageEngineB2, StorageEngineAzureBlob, } )
Functions ¶
Types ¶
type Application ¶
type ApplicationService ¶
type ApplicationService interface { Create(ctx context.Context, n *NewApplication) (*Application, error) Application(ctx context.Context, id string) (*Application, error) Applications(ctx context.Context, sinceID string, limit int) ([]*Application, error) Delete(ctx context.Context, id string) error Update(ctx context.Context, u *UpdateApplication) (*Application, error) FileBlobStorage(engine, accessKey, secretKey, region, endpoint string) (FileBlobStorage, error) }
ApplicationService defines the business logic for dealing with all aspects of an application.
type ApplicationStorage ¶
type ApplicationStorage interface { Store(ctx context.Context, n *NewApplication) (*Application, error) Application(ctx context.Context, id string) (*Application, error) Applications(ctx context.Context, sinceID string, limit int) ([]*Application, error) Delete(ctx context.Context, id string) error Update(ctx context.Context, u *UpdateApplication) (*Application, error) }
ApplicationStorage handles communication with the database for handling applications.
type EncryptionService ¶
type EncryptionService interface { Encrypt(plaintext []byte) ([]byte, error) EncryptToString(plaintext []byte) (string, error) Decrypt(cipherText []byte) ([]byte, error) DecryptString(cipherText string) ([]byte, error) }
EncryptionService manages the encrypting and decrypting of data
type File ¶
type File struct { ID string ApplicationID string Filename string FileBlobID string Size int64 MIMEType string MIMEValue string Extension string URL string Hash string Width int Height int CreatedAt time.Time UpdatedAt time.Time }
File holds all the "meta" data of a file. From its type and size to who uploaded it and what application it was uploaded to.
func (*File) IsTransformable ¶
type FileBlob ¶
type FileBlob struct { ID string Data io.ReadCloser MIMEValue string Size int64 // TempFileName this is used to determine if we need to delete the temp file after using the FileBlob TempFileName string }
FileBlob is holds the properties needed for the blob of a file.
func (*FileBlob) IsTransformable ¶
type FileBlobStorage ¶
type FileServeService ¶
type FileServeService interface {
Serve(ctx context.Context, path *url.URL, opts TransformationOption) (*FileBlob, error)
}
FileServeService handles serving the file over http
type FileService ¶
type FileService interface { Create(ctx context.Context, n *NewFile) (*File, error) File(ctx context.Context, id string) (*File, error) ApplicationFiles(ctx context.Context, applicationID, sinceID string, limit int) ([]*File, error) Delete(ctx context.Context, id string) error }
FileService defines the business logic for dealing with all aspects of a file.
type FileStorage ¶
type FileStorage interface { Store(ctx context.Context, n *NewFile) (*File, error) File(ctx context.Context, id string) (*File, error) FileByFileBlobID(ctx context.Context, fileBlobID string) (*File, error) ApplicationFiles(ctx context.Context, applicationID, sinceID string, limit int) ([]*File, error) Delete(ctx context.Context, id string) error }
FileStorage handles communication with the database for handling files.
type NewApplication ¶
type NewFile ¶
type NewFile struct { ApplicationID string Filename string FileBlobID string Size int64 MIMEType string MIMEValue string Extension string URL string Hash string Width int Height int }
NewFile is a helper struct for creating a new file
type NewTransformation ¶
type NewTransformation struct { ApplicationID string FileID string Actions TransformationOption }
type TotalUsage ¶
type TransformService ¶
type TransformStorage ¶
type TransformStorage interface {
Store(ctx context.Context, n *NewTransformation) (*Transformation, error)
}
type Transformation ¶
type TransformationOption ¶
type TransformationOption struct { // Width Width int // Height Height int // Format Format string // Quality the quality of the JPEG image defaults to 80. Quality int // Compression compression for a PNG image defaults to 6. Compression int // Crop uses lib vips smart crop to crop image Crop bool // Rotate image rotation angle. Must be a multiple of 90 Rotate int // Flip flips an image Flip bool // Flop flops an image Flop bool // Zoom Zoom int // black and white BW bool }