Skip to content

Commit

Permalink
refactor function to map int string
Browse files Browse the repository at this point in the history
  • Loading branch information
rchicoli committed Feb 19, 2017
1 parent cff8052 commit b3dac20
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,21 +523,21 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
cfg.AuthBasicUserFile = authBasicUserFile
}

if mainHTTPSnippets, exists, err := nginx.GetMapKeyAsMapStringString(cfgm.Data, "http-snippets", cfgm); exists {
if mainHTTPSnippets, exists, err := nginx.GetMapKeyAsMapIntString(cfgm.Data, "http-snippets", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.MainHTTPSnippets = mainHTTPSnippets
}
}
if locationSnippets, exists, err := nginx.GetMapKeyAsMapStringString(cfgm.Data, "location-snippets", cfgm); exists {
if locationSnippets, exists, err := nginx.GetMapKeyAsMapIntString(cfgm.Data, "location-snippets", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.LocationSnippets = locationSnippets
}
}
if serverSnippets, exists, err := nginx.GetMapKeyAsMapStringString(cfgm.Data, "server-snippets", cfgm); exists {
if serverSnippets, exists, err := nginx.GetMapKeyAsMapIntString(cfgm.Data, "server-snippets", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
}
}

if serverSnippets, exists, err := GetMapKeyAsMapStringString(ingEx.Ingress.Annotations, "nginx.org/server-snippets", ingEx.Ingress); exists {
if serverSnippets, exists, err := GetMapKeyAsMapIntString(ingEx.Ingress.Annotations, "nginx.org/server-snippets", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.ServerSnippets = serverSnippets
}
}
if locationSnippets, exists, err := GetMapKeyAsMapStringString(ingEx.Ingress.Annotations, "nginx.org/location-snippets", ingEx.Ingress); exists {
if locationSnippets, exists, err := GetMapKeyAsMapIntString(ingEx.Ingress.Annotations, "nginx.org/location-snippets", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
Expand Down
4 changes: 2 additions & 2 deletions nginx-controller/nginx/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func GetMapKeyAsStringSlice(m map[string]string, key string, context apiObject)
return nil, false, nil
}

// GetMapKeyAsMapStringString tries to find and parse a key in the map int as string
func GetMapKeyAsMapStringString(m map[string]string, key string, context apiObject) (map[int]string, bool, error) {
// GetMapKeyAsMapIntString tries to find and parse a key in the map int as string
func GetMapKeyAsMapIntString(m map[string]string, key string, context apiObject) (map[int]string, bool, error) {
lines := make(map[int]string, len(m[key]))
if str, exists := m[key]; exists {
for k, v := range strings.Split(str, "\n") {
Expand Down

0 comments on commit b3dac20

Please sign in to comment.