Documentation ¶
Index ¶
- Variables
- type Base
- func (g *Base[StackID, ImageID]) Clear()
- func (g *Base[StackID, ImageID]) DryRun(fn func(*Base[StackID, ImageID]) error) error
- func (g *Base[StackID, ImageID]) NewStack(id StackID, img Image[ImageID]) (Stack[StackID, ImageID], error)
- func (g *Base[StackID, ImageID]) NewVariant(stackID StackID, variantID ImageID, img image.Image) (Stack[StackID, ImageID], error)
- func (g *Base[StackID, ImageID]) RemoveStack(id StackID) (Stack[StackID, ImageID], error)
- func (g *Base[StackID, ImageID]) RemoveVariant(stackID StackID, imageID ImageID) (Image[ImageID], error)
- func (g *Base[StackID, ImageID]) ReplaceVariant(stackID StackID, variant Image[ImageID]) (Stack[StackID, ImageID], error)
- func (g *Base[StackID, ImageID]) Sort(sorting []StackID)
- func (g *Base[StackID, ImageID]) Tag(stackID StackID, tags ...string) (Stack[StackID, ImageID], error)
- func (g *Base[StackID, ImageID]) Untag(stackID StackID, tags ...string) (Stack[StackID, ImageID], error)
- type DTO
- type ID
- type Image
- type Stack
- func (s Stack[StackID, ImageID]) Clear() Stack[StackID, ImageID]
- func (s Stack[StackID, ImageID]) Clone() Stack[StackID, ImageID]
- func (s Stack[StackID, ImageID]) ContainsOriginal() bool
- func (s Stack[StackID, ImageID]) Image(id ImageID) (Image[ImageID], bool)
- func (s Stack[StackID, ImageID]) Last() Image[ImageID]
- func (s Stack[StackID, ImageID]) NewVariant(id ImageID, img image.Image) (Image[ImageID], error)
- func (s Stack[StackID, ImageID]) Original() Image[ImageID]
- func (s Stack[StackID, ImageID]) Tag(tags ...string) Stack[StackID, ImageID]
- func (s Stack[StackID, ImageID]) Untag(tags ...string) Stack[StackID, ImageID]
- func (s Stack[StackID, ImageID]) Variant(id ImageID) (Image[ImageID], bool)
- type Tags
Constants ¶
This section is empty.
Variables ¶
var ( // ErrEmptyID is returned when trying to add an [Image] with an empty id to // a [Stack], or when trying to create a [Stack] with an empty id. ErrEmptyID = errors.New("empty id") // ErrDuplicateID returned when trying to add a [Stack] with an ID that // already exists, or when trying to add an [Image] to a [Stack] that // already contains an [Image] with the same id. ErrDuplicateID = errors.New("duplicate id") // ErrStackNotFound is returned when a [Stack] cannot be found in a gallery. ErrStackNotFound = errors.New("stack not found in gallery") // ErrVariantNotFound is returned when an [Image] cannot be found in a [Stack]. ErrVariantNotFound = errors.New("variant not found in stack") )
Functions ¶
This section is empty.
Types ¶
type Base ¶
Base provides the core implementation for image galleries.
func New ¶
New returns a new gallery *Base that can be embedded into structs build galleries. The ID type of the gallery's stacks is specified by the StackID type parameter.
type MyGallery struct { *gallery.Base[string] } func NewGallery() *MyGallery { return &MyGallery{Base: gallery.New[string]()} }
func (*Base[StackID, ImageID]) Clear ¶ added in v0.0.12
func (g *Base[StackID, ImageID]) Clear()
Clear removes all stacks from the gallery.
func (*Base[StackID, ImageID]) DryRun ¶ added in v0.0.2
DryRun executes the given function and returns the error that is returned by that function. Any changes made to the gallery's stacks are reverted before returning.
func (*Base[StackID, ImageID]) NewStack ¶
func (g *Base[StackID, ImageID]) NewStack(id StackID, img Image[ImageID]) (Stack[StackID, ImageID], error)
NewStack adds a new Stack to the gallery. The provided Image will be the original image of the Stack, with its image.Metadata.Original field set to `true`. If the gallery already contains a Stack with the same id, the Stack is not added to the gallery, and an error that satisfies errors.Is(err, ErrDuplicateID) is returned. If the provided stack id or the provided image id is empty (zero value), an error that satisfies errors.Is(err, ErrEmptyID) is returned.
func (*Base[StackID, ImageID]) NewVariant ¶
func (g *Base[StackID, ImageID]) NewVariant(stackID StackID, variantID ImageID, img image.Image) (Stack[StackID, ImageID], error)
NewVariant adds an image as a new variant to the Stack with the given id, and returns the updated Stack that contains the new Image. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned.
func (*Base[StackID, ImageID]) RemoveStack ¶
RemoveStack removes the Stack with the given id from the gallery. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned.
func (*Base[StackID, ImageID]) RemoveVariant ¶
func (g *Base[StackID, ImageID]) RemoveVariant(stackID StackID, imageID ImageID) (Image[ImageID], error)
RemoveVariant removes a variant from the given Stack and returns the removed variant. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned. Similarly, if the Stack does not contain an Image with the given ImageID, an error that satisfies errors.Is(err, ErrImageNotFound) is returned.
func (*Base[StackID, ImageID]) ReplaceVariant ¶
func (g *Base[StackID, ImageID]) ReplaceVariant(stackID StackID, variant Image[ImageID]) (Stack[StackID, ImageID], error)
ReplaceVariant replaces a variant of the Stack with the given StackID. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned. Similarly, if the Stack does not contain an Image with the same id as the provided Image, an error that satisfies errors.Is(err, ErrImageNotFound) is returned.
func (*Base[StackID, ImageID]) Sort ¶
func (g *Base[StackID, ImageID]) Sort(sorting []StackID)
Sort sorts the gallery's stacks by the given sorting order.
func (*Base[StackID, ImageID]) Tag ¶
func (g *Base[StackID, ImageID]) Tag(stackID StackID, tags ...string) (Stack[StackID, ImageID], error)
Tag adds the given tags to the Stack with the given id, and returns the updated Stack. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned.
func (*Base[StackID, ImageID]) Untag ¶
func (g *Base[StackID, ImageID]) Untag(stackID StackID, tags ...string) (Stack[StackID, ImageID], error)
Untag removes the given tags from the Stack with the given id, and returns the updated Stack. If the gallery does not contain a Stack with the given id, an error that satisfies errors.Is(err, ErrStackNotFound) is returned.
type ID ¶ added in v0.0.4
type ID interface { comparable fmt.Stringer }
ID is the type constraint for [Stack]s and [Image]s of a gallery.
type Image ¶
type Image[ImageID ID] struct { image.Image ID ImageID `json:"id"` Original bool `json:"original"` }
Image is an image of a Stack. An image may be the original image of the stack, or a variant of the original image. The ID of an Image is unique within a Stack.
type Stack ¶
type Stack[StackID, ImageID ID] struct { ID StackID `json:"id"` Variants []Image[ImageID] `json:"variants"` Tags Tags `json:"tags"` }
A Stack represents one or multiple variants of the same image. For example, an image may exist in multiple sizes.
func (Stack[StackID, ImageID]) Clear ¶ added in v0.0.2
Clear returns a copy of the Stack will all variants removed except for the original.
func (Stack[StackID, ImageID]) ContainsOriginal ¶ added in v0.0.2
ContainsOriginal returns whether the Stack contains an Image that has its Original field set to true.
func (Stack[StackID, ImageID]) Image ¶
Image returns the Image with the given id, or false if the stack does not contain an Image with that id.
func (Stack[StackID, ImageID]) NewVariant ¶ added in v0.0.2
NewVariant returns a new gallery Image with the given id. No error is returned if the provided ImageID already exists in the Stack.
func (Stack[StackID, ImageID]) Original ¶
Original returns the original image of the stack, or the zero Image if the stack does not contain an original image.