Skip to content

huandu/go-singleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-singleton: Generic singleton factory

Build Status GoDoc

Starting from go1.18, Go will officially support generic. This package is designed to embrace the new technic for convenience.

Usage

Call Singleton with a given type name to get a pointer to this type.

type MyType struct {
    field int
}

v1 := singleton.Singleton[MyType]()
v1.field = 123

v2 := singleton.Singleton[MyType]()
println(v2.field) // Output: 123