Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huandu/go-singleton
Generic singleton for Go.
https://github.com/huandu/go-singleton
generics go singleton
Last synced: 29 days ago
JSON representation
Generic singleton for Go.
- Host: GitHub
- URL: https://github.com/huandu/go-singleton
- Owner: huandu
- License: mit
- Created: 2020-07-14T04:35:15.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-16T03:28:15.000Z (over 2 years ago)
- Last Synced: 2024-06-20T13:36:56.503Z (5 months ago)
- Topics: generics, go, singleton
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-singleton: Generic singleton factory
[![Build Status](https://github.com/huandu/go-singleton/workflows/Go/badge.svg)](https://github.com/huandu/go-singleton/actions)
[![GoDoc](https://godoc.org/github.com/huandu/go-singleton?status.svg)](https://pkg.go.dev/github.com/huandu/go-singleton)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.
```go
type MyType struct {
field int
}v1 := singleton.Singleton[MyType]()
v1.field = 123v2 := singleton.Singleton[MyType]()
println(v2.field) // Output: 123
```