Last active
July 25, 2022 16:04
-
-
Save rsperl/7c6aa4ecc2faf195bc87d2a23deca721 to your computer and use it in GitHub Desktop.
singleton #go #singleton #snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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