`sync.Once` ensures that a function is executed only once, even when called by multiple goroutines concurrently.
package main import ( "fmt" "sync" ) var once sync.Once var value string func initValue() { value = "initialized" } func GetValue() string { once.Do(initValue) return value } func main() { fmt.Println(GetValue()) }