diff options
| author | Jeff Carr <[email protected]> | 2025-09-03 14:04:47 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-03 14:04:47 -0500 |
| commit | d981b93728de9bfc513028c81fd0bf42cc5c838a (patch) | |
| tree | 36896b8f96d1678f637ccc7f2acc59528bdc4d2f /init.go | |
| parent | 98cc06ab8fc98b728107fff135b107dcdb56fb2a (diff) | |
finally a proper use for sync.Once
Diffstat (limited to 'init.go')
| -rw-r--r-- | init.go | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -23,9 +23,6 @@ func Default(opts ...OptionFunc) *Engine { } */ -// todo: use initOnce -// cache.go has Do() -// f.initOnce.Do(f.initWork) func Init() *Forge { f := InitPB() @@ -162,25 +159,27 @@ func (f *Forge) RawInitPB() { // try to NOT use the ENV settings anywhere but here // all initial ENV settings should be stored in the forge struct func (f *Forge) setenv() { - if err := fhelp.ConfigureENV(); err != nil { - log.Info("forge ConfigureENV() failed", err) - os.Exit(-1) - } - f.configDir = os.Getenv("FORGE_CONFIG") - f.goSrc = os.Getenv("FORGE_GOSRC") - f.repoPB = os.Getenv("FORGE_REPOPB") - f.forgeURL = os.Getenv("FORGE_URL") - f.patchDir = os.Getenv("FORGE_PATCHDIR") - if os.Getenv("FORGE_GOWORK") == "true" { - f.goWork = true - } - log.Printf("FORGE_CONFIG = %s\n", f.configDir) - log.Printf("FORGE_GOSRC = %s\n", f.goSrc) - log.Printf("FORGE_GOWORK = %v\n", f.goWork) - log.Printf("FORGE_REPOPB = %s\n", f.repoPB) - log.Printf("FORGE_URL = %s\n", f.forgeURL) - log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir) - log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME")) + f.once.Do(func() { + if err := fhelp.ConfigureENV(); err != nil { + log.Info("forge ConfigureENV() failed", err) + os.Exit(-1) + } + f.configDir = os.Getenv("FORGE_CONFIG") + f.goSrc = os.Getenv("FORGE_GOSRC") + f.repoPB = os.Getenv("FORGE_REPOPB") + f.forgeURL = os.Getenv("FORGE_URL") + f.patchDir = os.Getenv("FORGE_PATCHDIR") + if os.Getenv("FORGE_GOWORK") == "true" { + f.goWork = true + } + log.Printf("FORGE_CONFIG = %s\n", f.configDir) + log.Printf("FORGE_GOSRC = %s\n", f.goSrc) + log.Printf("FORGE_GOWORK = %v\n", f.goWork) + log.Printf("FORGE_REPOPB = %s\n", f.repoPB) + log.Printf("FORGE_URL = %s\n", f.forgeURL) + log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir) + log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME")) + }) } func (f *Forge) GetForgeURL() string { |
