Skip to content

Commit

Permalink
Utils: fix serialization cases in MapToString util
Browse files Browse the repository at this point in the history
Signed-off-by: nb-ohad <mitrani.ohad@gmail.com>
  • Loading branch information
nb-ohad committed Jul 29, 2024
1 parent 47babfb commit a5681f6
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions internal/utils/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,28 @@ func MapSlice[T, K any](in []T, mapper func(item T) K) []K {
return out
}

// maptostring serializes the provided map into a a string.
// MapToString serializes the provided map into a a string.
func MapToString[K, T ~string](m map[K]T, keyValueSeperator, itemSeperator string) string {
if len(m) == 0 {
return ""
}

// An item seperator is added before each item. For the first item we want

Check failure on line 95 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / codespell

seperator ==> separator

Check failure on line 95 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`seperator` is a misspelling of `separator` (misspell)

Check failure on line 95 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] reported by reviewdog 🐶 "seperator" is a misspelling of "separator" Raw Output: ./internal/utils/core.go:95:12: "seperator" is a misspelling of "separator"
// the seperator to be an empty string

Check failure on line 96 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / codespell

seperator ==> separator

Check failure on line 96 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / golangci-lint

`seperator` is a misspelling of `separator` (misspell)

Check failure on line 96 in internal/utils/core.go

View workflow job for this annotation

GitHub Actions / misspell

[misspell] reported by reviewdog 🐶 "seperator" is a misspelling of "separator" Raw Output: ./internal/utils/core.go:96:8: "seperator" is a misspelling of "separator"
itemSep := ""
bldr := strings.Builder{}
bldr.WriteString("--kernelmountoptions=")
for key, value := range m {
bldr.WriteString(itemSep)
bldr.WriteString(string(key))
bldr.WriteString(keyValueSeperator)
bldr.WriteString(string(value))
bldr.WriteString(itemSeperator)

// Skip value serialization if it evaluates to an empty string
valAsString := string(value)
if valAsString != "" {
bldr.WriteString(keyValueSeperator)
bldr.WriteString(valAsString)
}

itemSep = itemSeperator
}
return bldr.String()
}
Expand Down

0 comments on commit a5681f6

Please sign in to comment.