Last active
January 4, 2021 17:28
-
-
Save 178inaba/3f31d15cb20b092e26a5076cef13fcd4 to your computer and use it in GitHub Desktop.
Append map slice.
This file contains hidden or 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" | |
) | |
type foo struct { | |
i int | |
} | |
func main() { | |
m := map[int][]*foo{} | |
m[1] = append(m[1], &foo{i: 123}) | |
m[1] = append(m[1], &foo{i: 456}) | |
fmt.Println(m) | |
fmt.Println(m[1]) | |
fmt.Println(m[1][0]) | |
fmt.Println(m[1][1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment