finally a proper use for sync.Once
This commit is contained in:
parent
98cc06ab8f
commit
d981b93728
5
init.go
5
init.go
|
@ -23,9 +23,6 @@ func Default(opts ...OptionFunc) *Engine {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// todo: use initOnce
|
|
||||||
// cache.go has Do()
|
|
||||||
// f.initOnce.Do(f.initWork)
|
|
||||||
func Init() *Forge {
|
func Init() *Forge {
|
||||||
f := InitPB()
|
f := InitPB()
|
||||||
|
|
||||||
|
@ -162,6 +159,7 @@ func (f *Forge) RawInitPB() {
|
||||||
// try to NOT use the ENV settings anywhere but here
|
// try to NOT use the ENV settings anywhere but here
|
||||||
// all initial ENV settings should be stored in the forge struct
|
// all initial ENV settings should be stored in the forge struct
|
||||||
func (f *Forge) setenv() {
|
func (f *Forge) setenv() {
|
||||||
|
f.once.Do(func() {
|
||||||
if err := fhelp.ConfigureENV(); err != nil {
|
if err := fhelp.ConfigureENV(); err != nil {
|
||||||
log.Info("forge ConfigureENV() failed", err)
|
log.Info("forge ConfigureENV() failed", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
|
@ -181,6 +179,7 @@ func (f *Forge) setenv() {
|
||||||
log.Printf("FORGE_URL = %s\n", f.forgeURL)
|
log.Printf("FORGE_URL = %s\n", f.forgeURL)
|
||||||
log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir)
|
log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir)
|
||||||
log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME"))
|
log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forge) GetForgeURL() string {
|
func (f *Forge) GetForgeURL() string {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
// maybe an interface someday?
|
// maybe an interface someday?
|
||||||
type Forge struct {
|
type Forge struct {
|
||||||
// one-time initialized data
|
// one-time initialized data
|
||||||
initOnce sync.Once
|
once sync.Once
|
||||||
initErr error // init error, if any
|
initErr error // init error, if any
|
||||||
goSrc string // the path to go/src
|
goSrc string // the path to go/src
|
||||||
repoPB string // the path to the repos.pb cache file
|
repoPB string // the path to the repos.pb cache file
|
||||||
|
|
Loading…
Reference in New Issue