Skip to content

Commit

Permalink
lxd-metadata: Fix lint errors (revive: unchecked-type-assertion, var-…
Browse files Browse the repository at this point in the history
…naming).

Signed-off-by: Mark Laing <[email protected]>
  • Loading branch information
markylaing authored and tomponline committed Jul 23, 2024
1 parent e0d8071 commit eb60f37
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lxd/lxd-metadata/lxd_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,19 +347,19 @@ func parse(path string, outputJSONPath string, excludedPaths []string, substitut

func writeDocFile(inputJSONPath, outputTxtPath string) error {
countMaxBackTicks := func(s string) int {
count, curr_count := 0, 0
count, currCount := 0, 0
n := len(s)
for i := 0; i < n; i++ {
if s[i] == '`' {
curr_count++
currCount++
continue
}

if curr_count > count {
count = curr_count
if currCount > count {
count = currCount
}

curr_count = 0
currCount = 0
}

return count
Expand Down Expand Up @@ -389,18 +389,29 @@ func writeDocFile(inputJSONPath, outputTxtPath string) error {
for _, groupKey := range sortedGroupKeys {
groupEntries := entityEntries[groupKey]
buffer.WriteString(fmt.Sprintf("<!-- config group %s-%s start -->\n", entityKey, groupKey))
for _, configEntry := range groupEntries["keys"] {
for configKey, configContent := range configEntry.(map[string]any) {
for _, configEntryAny := range groupEntries["keys"] {
configEntry, ok := configEntryAny.(map[string]any)
if !ok {
return fmt.Errorf("Unexpected config entry type (%T) in group %q", configEntryAny, groupKey)
}

for configKey, configContentAny := range configEntry {
// There is only one key-value pair in each map
kvBuffer := bytes.NewBufferString("")
var backticksCount int
var longDescContent string
sortedConfigContentKeys := getSortedKeysFromMap(configContent.(map[string]any))
configContent, ok := configContentAny.(map[string]any)
if !ok {
return fmt.Errorf("Unexpected config content type (%T) for key %q in group %q", configContentAny, configKey, groupKey)
}

sortedConfigContentKeys := getSortedKeysFromMap(configContent)
for _, configEntryContentKey := range sortedConfigContentKeys {
configContentValue := configContent.(map[string]any)[configEntryContentKey]
configContentValue := configContent[configEntryContentKey]
if configEntryContentKey == "longdesc" {
backticksCount = countMaxBackTicks(configContentValue.(string))
longDescContent = configContentValue.(string)
configContentString, _ := configContentValue.(string)
backticksCount = countMaxBackTicks(configContentString)
longDescContent = configContentString
continue
}

Expand Down

0 comments on commit eb60f37

Please sign in to comment.