Skip to content

Instantly share code, notes, and snippets.

@gokhanm
Last active November 17, 2021 12:21
Show Gist options
  • Save gokhanm/99809cf9979edb447e8ad9ca7e52f971 to your computer and use it in GitHub Desktop.
Save gokhanm/99809cf9979edb447e8ad9ca7e52f971 to your computer and use it in GitHub Desktop.
singleton pattern in go
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