Created
September 27, 2021 22:27
-
-
Save FrenchBen/97a5fbe06799bc777637ad09962e57ad to your computer and use it in GitHub Desktop.
Golang range with a map[string] is non-deterministic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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