diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-29 10:44:09 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-29 10:44:09 +0100 |
commit | df20b05463fef42aba93d5208e410a7ecc56da5d (patch) | |
tree | ea09dcb297175ffd2d8c5d93174b9f9a91d8c27c /resource/resource.go | |
parent | 863a812e07193541b42732b0e227f3d320433f01 (diff) |
resource: Make resource counters for name and title independent
This is the most flexible with the current syntax, and probably what most people would expcect.
Updates #4335
Diffstat (limited to 'resource/resource.go')
-rw-r--r-- | resource/resource.go | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/resource/resource.go b/resource/resource.go index dfda1ae7a..da62db65c 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -464,10 +464,10 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...Resource) er } var ( - nameSet, titleSet bool - currentCounter = 0 - counterFound bool - resourceSrcKey = strings.ToLower(r.Name()) + nameSet, titleSet bool + nameCounter, titleCounter = 0, 0 + nameCounterFound, titleCounterFound bool + resourceSrcKey = strings.ToLower(r.Name()) ) ma := r.(metaAssigner) @@ -491,15 +491,16 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...Resource) er name, found := meta["name"] if found { name := cast.ToString(name) - if !counterFound { - counterFound = strings.Contains(name, counterPlaceHolder) + if !nameCounterFound { + nameCounterFound = strings.Contains(name, counterPlaceHolder) } - if counterFound && currentCounter == 0 { - currentCounter = counters[srcKey] + 1 - counters[srcKey] = currentCounter + if nameCounterFound && nameCounter == 0 { + counterKey := "name_" + srcKey + nameCounter = counters[counterKey] + 1 + counters[counterKey] = nameCounter } - ma.setName(replaceResourcePlaceholders(name, currentCounter)) + ma.setName(replaceResourcePlaceholders(name, nameCounter)) nameSet = true } } @@ -508,14 +509,15 @@ func AssignMetadata(metadata []map[string]interface{}, resources ...Resource) er title, found := meta["title"] if found { title := cast.ToString(title) - if !counterFound { - counterFound = strings.Contains(title, counterPlaceHolder) + if !titleCounterFound { + titleCounterFound = strings.Contains(title, counterPlaceHolder) } - if counterFound && currentCounter == 0 { - currentCounter = counters[srcKey] + 1 - counters[srcKey] = currentCounter + if titleCounterFound && titleCounter == 0 { + counterKey := "title_" + srcKey + titleCounter = counters[counterKey] + 1 + counters[counterKey] = titleCounter } - ma.setTitle((replaceResourcePlaceholders(title, currentCounter))) + ma.setTitle((replaceResourcePlaceholders(title, titleCounter))) titleSet = true } } |