| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "sort" |
| 6 | ) |
| 7 | |
| 8 | type Foo struct { |
| 9 | Name string |
| 10 | } |
| 11 | |
| 12 | func main() { |
| 13 | m := map[string]Foo{ |
| 14 | "hello": {Name: "bar"}, |
| 15 | "world": {Name: "machin"}, |
| 16 | } |
| 17 | |
| 18 | var content []string |
| 19 | |
| 20 | for key, value := range m { |
| 21 | content = append(content, key+value.Name) |
| 22 | } |
| 23 | |
| 24 | sort.Strings(content) |
| 25 | fmt.Println(content) |
| 26 | } |
| 27 | |
| 28 | // Output: |
| 29 | // [hellobar worldmachin] |