Skip to content

Instantly share code, notes, and snippets.

@maxclav
Last active December 19, 2022 03:45
Show Gist options
  • Save maxclav/2200c92d3cf3ed362b90d1fae0bdd03f to your computer and use it in GitHub Desktop.
Save maxclav/2200c92d3cf3ed362b90d1fae0bdd03f to your computer and use it in GitHub Desktop.
Singleton Design Pattern in Go (GoLang).
package designpattern
import (
"sync"
)
type singleton struct {}
var instance *singleton
var once sync.Once
// We could also call this GetInstance().
func Singleton() *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