reg

package module
v0.0.0-...-03b2f17 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 2 Imported by: 4

README

go-reg

Package reg implements a thread-safe registry, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-reg

GoDoc

Examples

Here is an example:

import "github.com/reiver/go-reg"

// ...

var registrar reg.Registry[MyCustomType]

// ...

var value MyCustomType // = ...

reg.Set(name, value)

// ...

value := reg.Get(name))

Import

To import package reg use import code like the follownig:

import "github.com/reiver/go-reg"

Installation

To install package reg do the following:

GOPROXY=direct go get github.com/reiver/go-reg

Author

Package reg was written by Charles Iliya Krempeaux

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Registerer

type Registerer[T any] interface {
	Get(name string) (value T, found bool)
	Len() int
	Set(name string, value T) (previous T, found bool)
	Unset(name string) (previous T, found bool)
}

type RegistererFuncs

type RegistererFuncs[T any] struct {
	GetFunc   func(name string) (value T, found bool)
	LenFunc   func() int
	SetFunc   func(name string, value T) (previous T, found bool)
	UnsetFunc func(name string) (previous T, found bool)
}

func (RegistererFuncs[T]) Get

func (receiver RegistererFuncs[T]) Get(name string) (value T, found bool)

func (RegistererFuncs[T]) Len

func (receiver RegistererFuncs[T]) Len() int

func (RegistererFuncs[T]) Set

func (receiver RegistererFuncs[T]) Set(name string, value T) (previous T, found bool)

func (RegistererFuncs[T]) Unset

func (receiver RegistererFuncs[T]) Unset(name string) (previous T, found bool)

type Registry

type Registry[T any] struct {
	// contains filtered or unexported fields
}

func (*Registry[T]) For

func (receiver *Registry[T]) For(fn func(Registerer[T], string, T))

For lets you iterate through all the items in the registry — it calls func 'fn' on each item in the registry.

Note that you should NOT call .Get(), .Set(), .Len(), or .Unset() from the `fn`. It will cause For to lock.

func (*Registry[T]) Get

func (receiver *Registry[T]) Get(name string) (value T, found bool)

Get return the item inthe registry registered under the name 'name'.

This should NOT be called from within the function passed to Registry.For. Doing so will cause a deadlock

func (*Registry[T]) Len

func (receiver *Registry[T]) Len() int

Len returns the number of items in the registry.

This should NOT be called from within the function passed to Registry.For. Doing so will cause a deadlock

func (*Registry[T]) Set

func (receiver *Registry[T]) Set(name string, value T) (previous T, found bool)

Set registers an item in the registry under the name 'name', but it also returns the previous item under the name 'name' if it existed.

This should NOT be called from within the function passed to Registry.For. Doing so will cause a deadlock

func (*Registry[T]) Unset

func (receiver *Registry[T]) Unset(name string) (previous T, found bool)

Unset removes an item in the registry under the name 'name', if it is there, and it also returns the previous item under the name 'name' if it existed.

This should NOT be called from within the function passed to Registry.For. Doing so will cause a deadlock

func (*Registry[T]) UnsetWhen

func (receiver *Registry[T]) UnsetWhen(name string, whenFunc func(T) bool) (previous T, found bool, when bool)

UnsetWhen removes an item in the registry under the name 'name', if it is there and the `whenFunc` returns true, and it also returns the previous item under the name 'name' if it existed.

This should NOT be called from within the function passed to Registry.For. Doing so will cause a deadlock

Jump to

Keyboard shortcuts

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