Skip to content

Commit 64e0672

Browse files
committed
CLEANUP/MINOR: set PlainValues only once a construction time
1 parent 5fd91d1 commit 64e0672

1 file changed

Lines changed: 10 additions & 17 deletions

File tree

k8s/gate/haproxy/storage/mapstorage.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,51 +57,43 @@ func NewMapsStorage(logger *slog.Logger, mapsBaseDir string) MapsStorage {
5757
}
5858

5959
func (m *MapsStorageDefault) GetListenerExactMatchMapFile(frontendName string) *maps.MapFileState {
60-
f := m.getMapFile(frontendName, MAP_LISTENER_EXACT_MATCH)
61-
f.PlainValues = true
62-
return f
60+
return m.getMapFile(frontendName, MAP_LISTENER_EXACT_MATCH, true)
6361
}
6462

6563
func (m *MapsStorageDefault) GetListenerWildcardMatchMapFile(frontendName string) *maps.MapFileState {
66-
f := m.getMapFile(frontendName, MAP_LISTENER_WILDCARD_MATCH)
67-
f.PlainValues = true
68-
return f
64+
return m.getMapFile(frontendName, MAP_LISTENER_WILDCARD_MATCH, true)
6965
}
7066

7167
func (m *MapsStorageDefault) GetListenerRouteExactMatchMapFile(frontendName string) *maps.MapFileState {
72-
f := m.getMapFile(frontendName, MAP_LISTENER_ROUTE_EXACT_MATCH)
73-
f.PlainValues = true
74-
return f
68+
return m.getMapFile(frontendName, MAP_LISTENER_ROUTE_EXACT_MATCH, true)
7569
}
7670

7771
func (m *MapsStorageDefault) GetListenerRouteWildcardMatchMapFile(frontendName string) *maps.MapFileState {
78-
f := m.getMapFile(frontendName, MAP_LISTENER_ROUTE_WILDCARD_MATCH)
79-
f.PlainValues = true
80-
return f
72+
return m.getMapFile(frontendName, MAP_LISTENER_ROUTE_WILDCARD_MATCH, true)
8173
}
8274

8375
func (m *MapsStorageDefault) GetPathExactMapFile(frontendName string) *maps.MapFileState {
84-
return m.getMapFile(frontendName, PATH_EXACT_MAP)
76+
return m.getMapFile(frontendName, PATH_EXACT_MAP, false)
8577
}
8678

8779
func (m *MapsStorageDefault) GetPathPrefixMapFile(frontendName string) *maps.MapFileState {
88-
return m.getMapFile(frontendName, PATH_PREFIX_MAP)
80+
return m.getMapFile(frontendName, PATH_PREFIX_MAP, false)
8981
}
9082

9183
func (m *MapsStorageDefault) GetPathRegexMapFile(frontendName string) *maps.MapFileState {
92-
return m.getMapFile(frontendName, PATH_REGEX_MAP)
84+
return m.getMapFile(frontendName, PATH_REGEX_MAP, false)
9385
}
9486

9587
func (m *MapsStorageDefault) GetSniMapFile(frontendName string) *maps.MapFileState {
96-
return m.getMapFile(frontendName, SNI_MAP)
88+
return m.getMapFile(frontendName, SNI_MAP, false)
9789
}
9890

9991
// getMapFile returns the MapFileState for the given frontend name and map name.
10092
// If the map file does not exist, it creates a new instance of MapFileState,
10193
// reads the map file from disk, and stores the map file in the mapFiles map.
10294
// If there is an error reading the map file from disk, it logs an error message.
10395
// It returns a pointer to the MapFileState.
104-
func (m *MapsStorageDefault) getMapFile(frontendName string, mapName string) *maps.MapFileState {
96+
func (m *MapsStorageDefault) getMapFile(frontendName string, mapName string, plainValues bool) *maps.MapFileState {
10597
mapBaseDir := filepath.Join(m.MapsBaseDir, frontendName)
10698
mapFileName := mapName + ".map"
10799

@@ -113,6 +105,7 @@ func (m *MapsStorageDefault) getMapFile(frontendName string, mapName string) *ma
113105
mapFile := mapFilesInDir[mapFileName]
114106
if mapFile == nil {
115107
mapFile = maps.NewMapFileState(mapBaseDir, mapFileName, m.logger)
108+
mapFile.PlainValues = plainValues
116109
m.mapFiles[mapBaseDir][mapFileName] = mapFile
117110
}
118111
return mapFile

0 commit comments

Comments
 (0)