go言語でのエラーの解決策が分かりません。
vscodeを用いて実行しています。
go
1package main 2 3import( 4 "fmt" 5) 6 7type Post struct{ 8 Id int 9 Content string 10 Author string 11} 12 13var PostById map[int]*Post 14var PostsByAuthor map[string][]*Post 15 16func store(post Post){ 17 PostById[post.Id] =&post 18 PostsByAuthor[post.Author]=append(PostsByAuthor[post.Author],&post) 19} 20 21func main(){ 22 PostById = make(map[int]*Post) 23 PostsByAuthor=make(map[string][]*Post) 24 25 post1:=Post{Id:1,Content:"Hello World!",Author: "Sau Sheong" } 26 post2:=Post{Id:2,Content:"Bonjour Monde!",Author: "Pierre" } 27 post3:=Post{Id:3,Content:"Hola Mundo!",Author: "Pedro" } 28 post4:=Post{Id:4,Content:"Greetings Earthlings!",Author: "Sheog" } 29 30 store(post1) 31 store(post2) 32 store(post3) 33 store(post4) 34 35 fmt.Println(PostById[1]) 36 fmt.Println(PostById[2]) 37 38 for _, post:=range PostsByAuthor["Sau Sheong"]{ 39 fmt.Println(post) 40 } 41 42 for _,post:=range PostsByAuthor["Pedro"]{ 43 fmt.Println(post) 44 } 45 46}
expected ';', found 'package'
exported type Post should have comment or be unexported
struct field Id should be ID
exported var PostById should have comment or be unexported
var PostById should be PostByID
exported var PostsByAuthor should have comment or be unexported
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。