// Maps formatted with %v show keys and values in their default formats.
// The %#v form (the # is called a "flag" in this context) shows the map in
- // the Go source format.
+ // the Go source format. Maps are printed in a consistent order, sorted
+ // by the values of the keys.
isLegume := map[string]bool{
- "peanut": true,
- // TODO: Include this line when maps are printed in deterministic order.
- // See Issue #21095
- // "dachshund": false,
+ "peanut": true,
+ "dachshund": false,
}
fmt.Printf("%v %#v\n", isLegume, isLegume)
- // Result: map[peanut:true] map[string]bool{"peanut":true}
+ // Result: map[dachshund:false peanut:true] map[string]bool{"dachshund":false, "peanut":true}
// Structs formatted with %v show field values in their default formats.
// The %+v form shows the fields by name, while %#v formats the struct in
// (110.7+22.5i) (110.7+22.5i) (110.70+22.50i) (1.11e+02+2.25e+01i)
// 128512 128512 😀 '😀' U+1F600 U+1F600 '😀'
// foo "bar" foo "bar" "foo \"bar\"" `foo "bar"`
- // map[peanut:true] map[string]bool{"peanut":true}
+ // map[dachshund:false peanut:true] map[string]bool{"dachshund":false, "peanut":true}
// {Kim 22} {Name:Kim Age:22} struct { Name string; Age int }{Name:"Kim", Age:22}
// &{Kim 22} 0x0
// [Katano Kobayashi Kurosawa Miyazaki Ozu] ["Katano" "Kobayashi" "Kurosawa" "Miyazaki" "Ozu"]