Documentation ¶
Index ¶
- Constants
- Variables
- func Create(id uuid.UUID, name string) command.Command
- func DeleteStack(galleryID, stackID uuid.UUID) command.Command
- func EventApplier(impl *Implementation) func(event.Event)
- func HandleCommands(ctx context.Context, h *command.Handler, galleries Repository, ...) <-chan error
- func RegisterCommands(r command.Registry)
- func RegisterEvents(r event.Registry)
- func RenameStack(galleryID, stackID uuid.UUID, name string) command.Command
- func TagStack(galleryID, stackID uuid.UUID, tags []string) command.Command
- func UntagStack(galleryID, stackID uuid.UUID, tags []string) command.Command
- func UpdateStack(galleryID uuid.UUID, stack Stack) command.Command
- type CreatedData
- type Gallery
- type Image
- type ImageReplacedData
- type ImageUploadedData
- type Implementation
- func (g *Implementation) Create(name string) error
- func (g *Implementation) Delete(ctx context.Context, storage media.Storage, stack Stack) error
- func (g *Implementation) FindByTag(tags ...string) []Stack
- func (g *Implementation) JSON() JSONGallery
- func (g *Implementation) MarshalSnapshot() ([]byte, error)
- func (g *Implementation) RenameStack(ctx context.Context, stackID uuid.UUID, name string) (Stack, error)
- func (g *Implementation) Replace(ctx context.Context, storage media.Storage, r io.Reader, stackID uuid.UUID) (Stack, error)
- func (g *Implementation) Stack(id uuid.UUID) (Stack, error)
- func (g *Implementation) Tag(ctx context.Context, stack Stack, tags ...string) (Stack, error)
- func (g *Implementation) UnmarshalSnapshot(b []byte) error
- func (g *Implementation) Untag(ctx context.Context, stack Stack, tags ...string) (Stack, error)
- func (g *Implementation) Update(id uuid.UUID, update func(Stack) Stack) error
- func (g *Implementation) Upload(ctx context.Context, storage media.Storage, r io.Reader, ...) (Stack, error)
- type JSONGallery
- type Lookup
- type PNGCompressor
- type PostProcessor
- type PostProcessorOption
- type ProcessingPipeline
- type Processor
- type ProcessorContext
- func (ctx *ProcessorContext) Encode(w io.Writer, img stdimage.Image, format string) error
- func (ctx *ProcessorContext) Encoder() image.Encoder
- func (ctx *ProcessorContext) Stack() Stack
- func (ctx *ProcessorContext) Storage() media.Storage
- func (ctx *ProcessorContext) Update(fn func(Stack) Stack) error
- type ProcessorFunc
- type Repository
- type Resizer
- type Stack
- type StackDeletedData
- type StackRenamedData
- type StackTaggedData
- type StackUntaggedData
- type StackUpdatedData
- type Stacks
Constants ¶
const ( CreateCommand = "cms.media.image.gallery.create" DeleteStackCommand = "cms.media.image.gallery.stack_deleted" TagStackCommand = "cms.media.image.gallery.stack_tagged" UntagStackCommand = "cms.media.image.gallery.stack_untagged" RenameStackCommand = "cms.media.image.gallery.stack_renamed" UpdateStackCommand = "cms.media.image.gallery.stack_updated" )
Gallery commands
const ( Created = "cms.media.image.gallery.created" ImageUploaded = "cms.media.image.gallery.image_uploaded" ImageReplaced = "cms.media.image.gallery.stack_replaced" StackDeleted = "cms.media.image.gallery.stack_deleted" StackTagged = "cms.media.image.gallery.stack_tagged" StackUntagged = "cms.media.image.gallery.stack_untagged" StackRenamed = "cms.media.image.gallery.stack_renamed" StackUpdated = "cms.media.image.gallery.stack_updated" )
const Aggregate = "cms.media.image.gallery"
Aggregate is the name of the Gallery aggregate.
Variables ¶
var ( // ErrEmptyName is returned when an empty name is provided to a Gallery. ErrEmptyName = errors.New("empty name") // ErrAlreadyCreated is returned when creating a Gallery that was created already. ErrAlreadyCreated = errors.New("already created") // ErrNotCreated is returned when trying to use a Gallery that hasn't been created yet. ErrNotCreated = errors.New("Gallery not created") // ErrNotFound is returned when a Gallery cannot be found within a Repository. ErrNotFound = errors.New("Gallery not found") // ErrStackNotFound is returned when a Stack cannot be found within a Gallery. ErrStackNotFound = errors.New("Stack not found") // ErrStackCorrupted is returned updating a Stack in an illegal way. ErrStackCorrupted = errors.New("stack corrupted") )
Functions ¶
func DeleteStack ¶
DeleteStack returns the command to delete an image from a gallery.
func EventApplier ¶
func EventApplier(impl *Implementation) func(event.Event)
EventApplier returns the event applier function for a gallery implementation.
func HandleCommands ¶
func HandleCommands(ctx context.Context, h *command.Handler, galleries Repository, storage media.Storage) <-chan error
HandleCommands handles commands until ctx is canceled.
func RegisterCommands ¶
func RegisterEvents ¶
func RenameStack ¶
RenameStack returns the command to rename an image of a gallery.
func UntagStack ¶
UntagStack returns the command to remove tags from an image of a gallery.
Types ¶
type CreatedData ¶
type CreatedData struct {
Name string
}
type Gallery ¶
type Gallery struct { *aggregate.Base *Implementation // contains filtered or unexported fields }
A Gallery is a collection of image stacks. A Stack may contain multiple variants of the same image in different sizes.
func (*Gallery) ApplyEvent ¶
type ImageReplacedData ¶
type ImageReplacedData struct {
Stack Stack
}
type ImageUploadedData ¶
type ImageUploadedData struct {
Stack Stack
}
type Implementation ¶
type Implementation struct { Name string `json:"name"` Stacks Stacks `json:"stacks"` // contains filtered or unexported fields }
Implementation can be embedded into structs to implement a Gallery.
type CustomGallery struct { *aggregate.Base *Implementation applyEvent func(event.Event) } func NewCustomGallery(id uuid.UUID) *Gallery { g := &CustomGallery{ Base: aggregate.New("custom-gallery", id) } g.Implementation, g.applyEvent = gallery.NewImplementation(g) } func (g *CustomGallery) ApplyEvent(evt event.Event) { g.applyEvent(evt) switch evt.Name() { case "my.custom-gallery.some_event": // handle custom events } }
func NewImplementation ¶
func NewImplementation(gallery aggregate.Aggregate) (*Implementation, func(event.Event))
NewImplementation returns the Implementation for the provided Gallery and the event applier for the implementation.
func (*Implementation) Create ¶
func (g *Implementation) Create(name string) error
Create creates the Gallery with the given name.
func (*Implementation) FindByTag ¶
func (g *Implementation) FindByTag(tags ...string) []Stack
FindByTag returns the Stacks that have all provided tags.
func (*Implementation) JSON ¶
func (g *Implementation) JSON() JSONGallery
JSON returns the JSONGallery for g.
func (*Implementation) MarshalSnapshot ¶
func (g *Implementation) MarshalSnapshot() ([]byte, error)
MarshalSnapshot implements snapshot.Marshaler.
func (*Implementation) RenameStack ¶
func (g *Implementation) RenameStack(ctx context.Context, stackID uuid.UUID, name string) (Stack, error)
RenameStack renames each Image in the given Stack to name.
func (*Implementation) Replace ¶
func (g *Implementation) Replace(ctx context.Context, storage media.Storage, r io.Reader, stackID uuid.UUID) (Stack, error)
Replace replaced the Images in the given Stack with the image in r.
func (*Implementation) Stack ¶
func (g *Implementation) Stack(id uuid.UUID) (Stack, error)
Stack returns the Stack with the given UUID or ErrStackNotFound.
func (*Implementation) UnmarshalSnapshot ¶
func (g *Implementation) UnmarshalSnapshot(b []byte) error
UnmarshalSnapshot implements snapshot.Unmarshaler.
type JSONGallery ¶
type JSONGallery struct { ID uuid.UUID `json:"id"` Name string `json:"name"` Stacks Stacks `json:"stacks"` }
JSONGallery is the JSON representation of a Gallery.
type Lookup ¶
type Lookup struct {
// contains filtered or unexported fields
}
Lookup provides lookup of Gallery UUIDs. It is thread-safe.
func (*Lookup) ApplyEvent ¶
ApplyEvent applies aggregate events.
func (*Lookup) GalleryName ¶
GalleryName returns the UUID of the Gallery with the give name, or false if Lookup has no UUID for name.
type PNGCompressor ¶
type PNGCompressor image.PNGCompressor
PNGCompressor is a Processor that compresses images using a png.Encoder with a png.CompressionLevel to compress the given image.
PNGCompressor compresses each Image in a Stack in parallel.
func (PNGCompressor) Process ¶
func (comp PNGCompressor) Process(ctx *ProcessorContext) error
Process runs the PNGCompressor on the given ProcessorContext.
type PostProcessor ¶
type PostProcessor struct {
// contains filtered or unexported fields
}
PostProcessor post-processed Stacks of Galleries.
func NewPostProcessor ¶
func NewPostProcessor(enc image.Encoder, storage media.Storage, galleries Repository) *PostProcessor
NewPostProcessor returns a PostProcessor.
func (*PostProcessor) Process ¶
func (svc *PostProcessor) Process(ctx context.Context, stack Stack, pipe ProcessingPipeline) (Stack, error)
Process calls pipe.Process with the provided Stack.
func (*PostProcessor) Run ¶
func (svc *PostProcessor) Run( ctx context.Context, bus event.Bus, pipe ProcessingPipeline, opts ...PostProcessorOption, ) (<-chan error, error)
Run starts the PostProcessor in the background and returns a channel of asynchronous processing errors. PostProcessor runs until ctx is canceled.
type PostProcessorOption ¶
type PostProcessorOption func(*postProcessorConfig)
PostProcessorOption is an option for PostProcessor.Run.
func OnProcessed ¶
func OnProcessed(fn func(Stack, *Gallery)) PostProcessorOption
OnProcessed returns a PostProcessorOption that registers fn as a callback function that is called when a Stack has been processed.
func ProcessorWorkers ¶
func ProcessorWorkers(workers int) PostProcessorOption
ProcessorWorkers returns a PostProcessorOption that configures the worker count for processing Stacks. Default & minimum workers is 1.
type ProcessingPipeline ¶
type ProcessingPipeline []Processor
A ProcessingPipeline is a collection of Processors that are run sequentially on a given Stack to post-process an image.
type Processor ¶
type Processor interface {
Process(*ProcessorContext) error
}
A Processor processes an image through a ProcessorContext.
type ProcessorContext ¶
ProcessorContext is passed to Processors when they process a Stack. The ProcessorContext provides the Stack and image related functions or services to the Processors.
func (*ProcessorContext) Encode ¶
Encode encodes an image using the appropriate encoder for the specified image format.
func (*ProcessorContext) Encoder ¶
func (ctx *ProcessorContext) Encoder() image.Encoder
Encoder returns the ImageEncoder.
func (*ProcessorContext) Stack ¶
func (ctx *ProcessorContext) Stack() Stack
Stack returns the processed Stack.
func (*ProcessorContext) Storage ¶
func (ctx *ProcessorContext) Storage() media.Storage
Storage returns the media storage.
type ProcessorFunc ¶
type ProcessorFunc func(*ProcessorContext) error
ProcessorFunc allows a function to be used as a Processor.
func (ProcessorFunc) Process ¶
func (fn ProcessorFunc) Process(ctx *ProcessorContext) error
Process calls fn(ctx).
type Repository ¶
type Repository interface { // Save saves a Gallery. Save(context.Context, *Gallery) error // Fetch fetches the Gallery with the given UUID or ErrNotFound. Fetch(context.Context, uuid.UUID) (*Gallery, error) // Delete deletes a Gallery. Delete(context.Context, *Gallery) error // Use fetches the Gallery with the given UUID, calls the provided function // with that Gallery and saves the Gallery into the repository. If the // function returns a non-nil error, the Gallery is not saved and that error // is returned. Use(context.Context, uuid.UUID, func(*Gallery) error) error }
Repository handles persistence of Galleries.
func GoesRepository ¶
func GoesRepository(repo aggregate.Repository) Repository
GoesRepository returns a Repository that uses an aggregate.Repository under the hood.
type Resizer ¶
A Resizer is a Processor that resizes the original Image of a Stack into additional dimensions.
func (Resizer) Process ¶
func (r Resizer) Process(ctx *ProcessorContext) error
Process runs the Resizer on the Stack in the given ProcessorContext.
type Stack ¶
A Stack represents an image in a gallery. A Stack may have multiple variants of an image.
func (Stack) WithTag ¶
WithTag adds the given tags to each Image in the Stack and returns the updated Stack. The original Stack is not modified.
func (Stack) WithoutTag ¶
WithoutTag removes the given tags from each Image and returns the updated Stack. The original Stack is not modified.
type StackDeletedData ¶
type StackDeletedData struct {
Stack Stack
}
type StackRenamedData ¶
type StackTaggedData ¶
type StackUntaggedData ¶
type StackUpdatedData ¶
type StackUpdatedData struct {
Stack Stack
}
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mock_gallery is a generated GoMock package.
|
Package mock_gallery is a generated GoMock package. |