reg

package module
v0.0.0-...-93a5107 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: MIT Imports: 2 Imported by: 3

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 https://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 Registry

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

func (*Registry[T]) For

func (receiver *Registry[T]) For(fn func(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'.

func (*Registry[T]) Len

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

Len returns the number of items in the registry.

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.

func (*Registry[T]) Unset

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

Unset removed 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.

func (*Registry[T]) UnsetWhen

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

Jump to

Keyboard shortcuts

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