@@ -60,6 +60,11 @@ type GenVarsiface interface {
6060 ConfigOutputPath () string
6161}
6262
63+ type muRawMap struct {
64+ sync.RWMutex
65+ tokenMap ParsedMap
66+ }
67+
6368// GenVars is the main struct holding the
6469// strategy patterns iface
6570// any initialised config if overridded with withers
@@ -72,8 +77,7 @@ type GenVars struct {
7277 config GenVarsConfig
7378 outString []string
7479 // rawMap is the internal object that holds the values of original token => retrieved value - decrypted in plain text
75- rawMap ParsedMap
76- mu sync.RWMutex
80+ rawMap muRawMap //ParsedMap
7781}
7882
7983// setValue implements GenVarsiface
@@ -100,7 +104,7 @@ func newGenVars() *GenVars {
100104 keySeparator : keySeparator ,
101105 }
102106 return & GenVars {
103- rawMap : m ,
107+ rawMap : muRawMap { tokenMap : m } ,
104108 ctx : context .TODO (),
105109 // return using default config
106110 config : defaultConf ,
@@ -134,20 +138,20 @@ func (c *GenVars) ConfigOutputPath() string {
134138}
135139
136140func (c * GenVars ) RawMap () ParsedMap {
137- c .mu .RLock ()
138- defer c .mu .RUnlock ()
141+ c .rawMap .RLock ()
142+ defer c .rawMap .RUnlock ()
139143 // make a copy of the map
140144 m := make (ParsedMap )
141- for k , v := range c .rawMap {
145+ for k , v := range c .rawMap . tokenMap {
142146 m [k ] = v
143147 }
144148 return m
145149}
146150
147151func (c * GenVars ) AddRawMap (key , val string ) {
148- c .mu .Lock ()
149- defer c .mu .Unlock ()
150- c .rawMap [key ] = c .keySeparatorLookup (key , val )
152+ c .rawMap .Lock ()
153+ defer c .rawMap .Unlock ()
154+ c .rawMap . tokenMap [key ] = c .keySeparatorLookup (key , val )
151155}
152156
153157// GenVarsConfig defines the input config object to be passed
@@ -317,11 +321,11 @@ func (c *GenVars) ConvertToExportVar() []string {
317321 for k , v := range c .RawMap () {
318322 rawKeyToken := strings .Split (k , "/" ) // assumes a path like token was used
319323 topLevelKey := rawKeyToken [len (rawKeyToken )- 1 ]
320- trm := & ParsedMap {}
321- if parsedOk := isParsed (v , trm ); parsedOk {
324+ trm := make ( ParsedMap )
325+ if parsedOk := isParsed (v , & trm ); parsedOk {
322326 // if is a map
323327 // try look up on key if separator defined
324- normMap := c .envVarNormalize (* trm )
328+ normMap := c .envVarNormalize (trm )
325329 c .exportVars (normMap )
326330 continue
327331 }
@@ -332,7 +336,7 @@ func (c *GenVars) ConvertToExportVar() []string {
332336
333337// envVarNormalize
334338func (c * GenVars ) envVarNormalize (pmap ParsedMap ) ParsedMap {
335- normalizedMap := ParsedMap {}
339+ normalizedMap := make ( ParsedMap )
336340 for k , v := range pmap {
337341 normalizedMap [c .normalizeKey (k )] = v
338342 }
0 commit comments