linker

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link[T comparable, I any] struct {
	Key   T
	Value I
}
func NewLink[T comparable, I any](key T, value I) *Link[T, I]

type Linker

type Linker[T comparable, I any] struct {
	// contains filtered or unexported fields
}

Linker stores typed values (I) indexed by keys of type T. It combines a Mapper for case-insensitive string lookups with a direct key→value map, allowing access both by string name and by typed key.

This is useful for plugin systems, strategy patterns, or any scenario where you need to select implementations by name while maintaining type safety.

Example:

//go:generate stringer -type=Driver

type Driver uint8
const (
    Postgres Driver = 0
    MySQL    Driver = 1
)

linker := NewLinker(
    NewLink(Postgres, &PGDriver{}),
    NewLink(MySQL, &MySQLDriver{}),
)
driver, _ := linker.GetByName("postgres") // returns &PGDriver{}

func NewLinker

func NewLinker[T comparable, I any](links ...*Link[T, I]) *Linker[T, I]

func (*Linker[T, I]) Add

func (linker *Linker[T, I]) Add(key T, value I)

func (*Linker[T, I]) All

func (linker *Linker[T, I]) All() iter.Seq2[T, I]

func (*Linker[T, I]) Get

func (linker *Linker[T, I]) Get(key T) (I, error)

func (*Linker[T, I]) GetOrDefault

func (linker *Linker[T, I]) GetOrDefault(key T, d I) I

func (*Linker[T, I]) Has

func (linker *Linker[T, I]) Has(key T) bool

func (*Linker[T, I]) Keys added in v0.0.8

func (linker *Linker[T, I]) Keys() []T

func (*Linker[T, I]) Len added in v0.0.7

func (linker *Linker[T, I]) Len() int

func (*Linker[T, I]) Remove

func (linker *Linker[T, I]) Remove(key T)

Jump to

Keyboard shortcuts

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