github.com/andy2046/gopie@v0.7.0/pkg/singleton/singleton.go (about)

     1  // Package singleton provides a singleton implementation.
     2  package singleton
     3  
     4  import "sync"
     5  
     6  // Instance is the singleton instance.
     7  type Instance struct {
     8  	Values map[interface{}]interface{}
     9  }
    10  
    11  var (
    12  	once     sync.Once
    13  	instance *Instance
    14  )
    15  
    16  // New returns the singleton instance.
    17  func New() *Instance {
    18  	once.Do(func() {
    19  		instance = &Instance{
    20  			Values: make(map[interface{}]interface{}),
    21  		}
    22  	})
    23  	return instance
    24  }