huandu / go-singleton

Generic singleton for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Generic singleton for Go.

License:MIT License


Languages

Language:Go 100.0%