gallery

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

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

type Base[StackID, ImageID ID] struct {
	DTO[StackID, ImageID]
}

Base provides the core implementation for image galleries.

func New

func New[StackID, ImageID ID]() *Base[StackID, ImageID]

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

func (g *Base[StackID, ImageID]) DryRun(fn func(*Base[StackID, ImageID]) error) error

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

func (g *Base[StackID, ImageID]) RemoveStack(id StackID) (Stack[StackID, ImageID], error)

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 DTO

type DTO[StackID, ImageID ID] struct {
	Stacks []Stack[StackID, ImageID] `json:"stacks"`
}

DTO provides the fields for *Base.

func (DTO[StackID, ImageID]) Stack added in v0.0.13

func (dto DTO[StackID, ImageID]) Stack(id StackID) (Stack[StackID, ImageID], bool)

Stack returns the Stack with the given id, or false if no the gallery does not contain a Stack with the id.

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.

func (Image[ID]) Clone added in v0.0.2

func (img Image[ID]) Clone() Image[ID]

Clone returns a deep-copy of the image.

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 ZeroStack added in v0.0.2

func ZeroStack[StackID, ImageID ID]() (zero Stack[StackID, ImageID])

ZeroStack returns the zero-value Stack.

func (Stack[StackID, ImageID]) Clear added in v0.0.2

func (s Stack[StackID, ImageID]) Clear() Stack[StackID, ImageID]

Clear returns a copy of the Stack will all variants removed except for the original.

func (Stack[StackID, ImageID]) Clone added in v0.0.2

func (s Stack[StackID, ImageID]) Clone() Stack[StackID, ImageID]

Clone returns a deep-copy of the Stack.

func (Stack[StackID, ImageID]) ContainsOriginal added in v0.0.2

func (s Stack[StackID, ImageID]) ContainsOriginal() bool

ContainsOriginal returns whether the Stack contains an Image that has its Original field set to true.

func (Stack[StackID, ImageID]) Image

func (s Stack[StackID, ImageID]) Image(id ImageID) (Image[ImageID], bool)

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]) Last added in v0.0.2

func (s Stack[StackID, ImageID]) Last() Image[ImageID]

Last returns the last Image of the Stack.

func (Stack[StackID, ImageID]) NewVariant added in v0.0.2

func (s Stack[StackID, ImageID]) NewVariant(id ImageID, img image.Image) (Image[ImageID], error)

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

func (s Stack[StackID, ImageID]) Original() Image[ImageID]

Original returns the original image of the stack, or the zero Image if the stack does not contain an original image.

func (Stack[StackID, ImageID]) Tag

func (s Stack[StackID, ImageID]) Tag(tags ...string) Stack[StackID, ImageID]

Tag returns a copy of the Stack with the given tags added.

func (Stack[StackID, ImageID]) Untag

func (s Stack[StackID, ImageID]) Untag(tags ...string) Stack[StackID, ImageID]

Tag returns a copy of the Stack with the given tags removed.

func (Stack[StackID, ImageID]) Variant added in v0.0.2

func (s Stack[StackID, ImageID]) Variant(id ImageID) (Image[ImageID], bool)

Variant is an alias for s.Image.

type Tags

type Tags = imgtools.Tags

Tags are the tags of a Stack.

func NewTags added in v0.0.2

func NewTags(tags ...string) Tags

NewTags returns a new Tags with the given tags. Duplicates are removed.

Jump to

Keyboard shortcuts

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