Skip to content

Instantly share code, notes, and snippets.

@FrenchBen
Created September 27, 2021 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrenchBen/97a5fbe06799bc777637ad09962e57ad to your computer and use it in GitHub Desktop.
Save FrenchBen/97a5fbe06799bc777637ad09962e57ad to your computer and use it in GitHub Desktop.
Golang range with a map[string] is non-deterministic
package main
import (
"fmt"
)
func main() {
subcharts := make(map[string][]string)
for i := 1; i < 4; i++ {
cname := fmt.Sprintf("package-%d.0.0.tgz", i)
subcharts[cname] = append(subcharts[cname], fmt.Sprintf("package%d.yml", i))
}
fmt.Printf("Subcharts: %v\n", subcharts)
for n, files := range subcharts {
fmt.Printf("Looking at %s - Chart: %s\n", n, files)
}
}
$ go run main.go
Subcharts: map[package-1.0.0.tgz:[package1.yml] package-2.0.0.tgz:[package2.yml] package-3.0.0.tgz:[package3.yml]]
Looking at package-1.0.0.tgz - Chart: [package1.yml]
Looking at package-2.0.0.tgz - Chart: [package2.yml]
Looking at package-3.0.0.tgz - Chart: [package3.yml]
$ go run main.go
Subcharts: map[package-1.0.0.tgz:[package1.yml] package-2.0.0.tgz:[package2.yml] package-3.0.0.tgz:[package3.yml]]
Looking at package-1.0.0.tgz - Chart: [package1.yml]
Looking at package-2.0.0.tgz - Chart: [package2.yml]
Looking at package-3.0.0.tgz - Chart: [package3.yml]
$ go run main.go
Subcharts: map[package-1.0.0.tgz:[package1.yml] package-2.0.0.tgz:[package2.yml] package-3.0.0.tgz:[package3.yml]]
Looking at package-2.0.0.tgz - Chart: [package2.yml]
Looking at package-3.0.0.tgz - Chart: [package3.yml]
Looking at package-1.0.0.tgz - Chart: [package1.yml]
$ go run main.go
Subcharts: map[package-1.0.0.tgz:[package1.yml] package-2.0.0.tgz:[package2.yml] package-3.0.0.tgz:[package3.yml]]
Looking at package-1.0.0.tgz - Chart: [package1.yml]
Looking at package-2.0.0.tgz - Chart: [package2.yml]
Looking at package-3.0.0.tgz - Chart: [package3.yml]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment