Skip to content

Instantly share code, notes, and snippets.

@andboson
Last active August 29, 2015 14:24
Show Gist options
  • Save andboson/49a7e6b1fdd57389d261 to your computer and use it in GitHub Desktop.
Save andboson/49a7e6b1fdd57389d261 to your computer and use it in GitHub Desktop.
singleton pattern in go
package singleton
import (
"sync"
)
//http://marcio.io/2015/07/singleton-pattern-in-go/
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