Skip to content

Instantly share code, notes, and snippets.

@aug2uag
Forked from adohe-zz/singleton.go
Created November 5, 2019 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aug2uag/44cf7746039de5db622e6b05b3caf055 to your computer and use it in GitHub Desktop.
Save aug2uag/44cf7746039de5db622e6b05b3caf055 to your computer and use it in GitHub Desktop.
Golang singleton implementation
package singleton
import (
"sync"
)
type singleton struct {
}
var instance *singleton
var once sync.Once
func GetInstance() *singleton {
once.Do(func() {
instance = &singleton{}
})
return instance
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment