Merge "Freeze environment reading after saving deps"
This commit is contained in:
commit
8a12ccd282
1 changed files with 9 additions and 2 deletions
|
@ -50,6 +50,7 @@ type config struct {
|
|||
|
||||
envLock sync.Mutex
|
||||
envDeps map[string]string
|
||||
envFrozen bool
|
||||
}
|
||||
|
||||
type jsonConfigurable interface {
|
||||
|
@ -178,6 +179,9 @@ func (c *config) Getenv(key string) string {
|
|||
var exists bool
|
||||
c.envLock.Lock()
|
||||
if val, exists = c.envDeps[key]; !exists {
|
||||
if c.envFrozen {
|
||||
panic("Cannot access new environment variables after envdeps are frozen")
|
||||
}
|
||||
val = os.Getenv(key)
|
||||
c.envDeps[key] = val
|
||||
}
|
||||
|
@ -186,6 +190,9 @@ func (c *config) Getenv(key string) string {
|
|||
}
|
||||
|
||||
func (c *config) EnvDeps() map[string]string {
|
||||
c.envLock.Lock()
|
||||
c.envFrozen = true
|
||||
c.envLock.Unlock()
|
||||
return c.envDeps
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue