singleton

package
v0.0.0-...-436d200 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2023 License: BSD-3-Clause Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Singleton

type Singleton interface {
	// Return the encapsulated singleton
	Get() (interface{}, error)
}

Interface for accessing singleton objects.

Example use: var configSelectorSingleton = NewSingleton(init)

func configSelector() (configSelector, error) {
    s, err := configSelectorSingleton.Get()
    if err != nil {
        return nil, err
    }
    return s.(configSelector), nil
}

func NewSingleton

func NewSingleton(init SingletonInitFunc) Singleton

Call to create a new singleton that is instantiated with the given init function. init is not called until the first invocation of Get(). If init errors, it will be called again on the next invocation of Get().

type SingletonInitFunc

type SingletonInitFunc func() (interface{}, error)

Jump to

Keyboard shortcuts

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