When you don't want to sully your package with globals, don't worry because totally-not-a-global
will sully itself
instead.
package main
import (
"fmt"
totallynotaglobal "github.com/willabides/totally-not-a-global"
)
func main() {
totallynotaglobal.Set("foo", "bar")
totallynotaglobal.SetOnce("baz", func() interface{} {
return "qux"
})
totallynotaglobal.SetOnce("baz", func() interface{} {
return "not qux"
})
foo, ok := totallynotaglobal.Get("foo")
if ok {
fmt.Print(foo)
}
totallynotaglobal.WithTotallyNotAGlobalValue("baz", func(notAGlobalValue interface{}) {
fmt.Println(notAGlobalValue)
})
}