Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active July 25, 2022 16:04
Show Gist options
  • Save rsperl/7c6aa4ecc2faf195bc87d2a23deca721 to your computer and use it in GitHub Desktop.
Save rsperl/7c6aa4ecc2faf195bc87d2a23deca721 to your computer and use it in GitHub Desktop.
singleton #go #singleton #snippet
import "sync"
var (
r *repository
once sync.Once
)
func Repository() *repository {
if r == nil {
once.Do(func() {
r = &repository{
items: make(map[string]string),
}
})
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment