singleton

package
v0.0.0-...-e1aa8c7 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

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)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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