registry

package
v0.0.0-...-7fd672d Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound         = errors.New("not found")
	ErrCannotDelete     = errors.New("cannot delete")
	ErrInvalidConfig    = errors.New("invalid config")
	ErrFieldRequired    = errors.New("field required")
	ErrAlreadyExists    = errors.New("already exists")
	ErrBadDataStructure = errors.New("bad data structure")
)

Functions

func Register

func Register(name string, f SetFunc)

Register registers a new registry set func. It panics if the name is already registered. It is intended to be called from the init function in the registry set package. It is NOT safe for concurrent use.

func Registries

func Registries() map[string]SetFunc

Registries returns a map of registered registry set funcs. It can be used concurrently with itself, but not with Register or Unregister.

func RegistryNames

func RegistryNames() []string

RegistryNames returns a slice of registered registry set names.

func Unregister

func Unregister(name string)

Unregister unregisters a registry set func. It is intended to be called from tests. It is NOT safe for concurrent use.

Types

type AreaRegistry

type AreaRegistry interface {
	Registry[models.Area]

	AddCommodity(areaID, commodityID string) error
	GetCommodities(areaID string) ([]string, error)
	DeleteCommodity(areaID, commodityID string) error
}

type CommodityRegistry

type CommodityRegistry interface {
	Registry[models.Commodity]

	AddImage(commodityID, imageID string) error
	GetImages(commodityID string) ([]string, error)
	DeleteImage(commodityID, imageID string) error

	AddManual(commodityID, manualID string) error
	GetManuals(commodityID string) ([]string, error)
	DeleteManual(commodityID, manualID string) error

	AddInvoice(commodityID, invoiceID string) error
	GetInvoices(commodityID string) ([]string, error)
	DeleteInvoice(commodityID, invoiceID string) error
}

type Config

type Config string

func (Config) Parse

func (c Config) Parse() (*url.URL, error)

type IDable

type IDable interface {
	GetID() string
	SetID(id string)
}

type ImageRegistry

type ImageRegistry interface {
	Registry[models.Image]
}

type InvoiceRegistry

type InvoiceRegistry interface {
	Registry[models.Invoice]
}

type LocationRegistry

type LocationRegistry interface {
	Registry[models.Location]

	AddArea(locationID, areaID string) error
	GetAreas(locationID string) ([]string, error)
	DeleteArea(locationID, areaID string) error
}

type ManualRegistry

type ManualRegistry interface {
	Registry[models.Manual]
}

type PIDable

type PIDable[T any] interface {
	*T
	IDable
}

type Registry

type Registry[T any] interface {
	// Create creates a new T in the registry.
	Create(T) (*T, error)

	// Get returns a T from the registry.
	Get(id string) (*T, error)

	// List returns a list of Ts from the registry.
	List() ([]*T, error)

	// Update updates a T in the registry.
	Update(T) (*T, error)

	// Delete deletes a T from the registry.
	Delete(id string) error

	// Count returns the number of Ts in the registry.
	Count() (int, error)
}

type Set

type Set struct {
	LocationRegistry  LocationRegistry
	AreaRegistry      AreaRegistry
	CommodityRegistry CommodityRegistry
	ImageRegistry     ImageRegistry
	InvoiceRegistry   InvoiceRegistry
	ManualRegistry    ManualRegistry
}

func (*Set) Validate

func (s *Set) Validate() error

type SetFunc

type SetFunc func(Config) (*Set, error)

func GetRegistry

func GetRegistry(conf string) (SetFunc, bool)

Directories

Path Synopsis
dbx

Jump to

Keyboard shortcuts

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