godropbox: github.com/dropbox/godropbox/singleton Index | Files

package singleton

import "github.com/dropbox/godropbox/singleton"

Index

Package Files

singleton.go

type Singleton Uses

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 Uses

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 Uses

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

Package singleton imports 2 packages (graph) and is imported by 4 packages. Updated 2016-07-31. Refresh now. Tools for package owners.