Goの型の宣言、値の代入とかをゴーっとメモってみた

# これは何？
あまりにも不自由なので、思い当たるところでよく使いそうな型をTL;DR的にメモ。

```golang:a.go

package main

import (
    "fmt"
)

func main() {
package main

import (
    "fmt"
)

func main() {
    la1 := make(map[string]string)
    la1["go"] = "golang"
    la1["rb"] = "ruby"
    la1["js"] = "javascript"
    fmt.Printf("la1=[%v]\n", la1)
    fmt.Println()

    la2 := make(map[int]string)
    la2[0] = "golang"
    la2[1] = "ruby"
    la2[2] = "javascript"
    fmt.Printf("la2=[%v]\n", la2)
    fmt.Println()

    la3 := make(map[string][]string)
    la3["a"] = append(la3["a"], "golang")
    la3["b"] = []string{"topaz", "ruby"}
    la3["b"] = append(la3["b"], "garnet")
    la3["c"] = append(la3["c"], "javascript")
    fmt.Printf("la3=[%v]\n", la3)
    fmt.Printf(" >> la3[\"b\"][1]=[%s]\n", la3["b"][1])
    fmt.Println()

    la4 := make(map[string]map[string][]string)
    la4["a"] = make(map[string][]string)
    la4["a"]["b"] = append(la4["a"]["b"], "golang")
    la4["b"] = make(map[string][]string)
    la4["b"]["n"] = append(la4["a"]["b"], "ruby")
    fmt.Printf("la4=[%v]\n", la4)
    fmt.Printf(" >> la4[\"b\"][\"n\"]=[%v]\n", la4["b"]["n"])
    fmt.Printf(" >> la4[\"b\"][\"n\"][1]=[%v]\n", la4["b"]["n"][1])
    fmt.Println()

    la5 := make(map[string]map[string]string)
    la5["a"] = make(map[string]string)
    la5["a"]["b"] = "golang"
    la5["b"] = make(map[string]string)
    la5["b"]["a"] = "javascript"
    la5["b"]["d"] = "ruby"
    fmt.Printf("la5=[%v]\n", la5)
    fmt.Printf(" >> la5[\"b\"][\"d\"]=[%s]\n", la5["b"]["d"])
    fmt.Println()

    la6 := make(map[int]map[string][]string)
    la6[2] = make(map[string][]string)
    la6[2]["b"] = []string{"javascript", "scala"}
    la6[2]["b"] = append(la6[2]["b"], "golang")
    la6[8] = make(map[string][]string)
    la6[8]["n"] = append(la6[8]["n"], "ruby")
    fmt.Printf("la6=[%v]\n", la6)
    fmt.Printf(" >> la6[2][\"b\"]=[%v]\n", la6[2]["b"])
    fmt.Printf(" >> la6[8][\"n\"]=[%v]\n", la6[2]["b"])
    fmt.Printf(" >> la6[8][\"n\"][0]=[%v]\n", la6[8]["n"][0])
    fmt.Println()

    la7 := make(map[int]map[int][]string)
    la7[2] = make(map[int][]string)
    la7[2][3] = []string{"javascript", "scala"}
    la7[2][3] = append(la7[2][3], "golang")
    la7[8] = make(map[int][]string)
    la7[8][5] = []string{"javascript", "ruby"}
    la7[8][5] = append(la7[8][5], "node.js")
    fmt.Printf("la7=[%v]\n", la7)
    fmt.Printf(" >> la7[2][3]=[%v]\n", la7[2][3])
    fmt.Printf(" >> la7[2][3][0]=[%v]\n", la7[2][3][0])
    fmt.Printf(" >> la7[8][5][2]=[%v]\n", la7[8][5][2])
    fmt.Println()

}

```

```shell:Result
$ go run a.go; 
la1=[map[rb:ruby js:javascript go:golang]]

la2=[map[0:golang 1:ruby 2:javascript]]

la3=[map[a:[golang] b:[topaz ruby garnet] c:[javascript]]]
 >> la3["b"][1]=[ruby]

la4=[map[a:map[b:[golang]] b:map[n:[golang ruby]]]]
 >> la4["b"]["n"]=[[golang ruby]]
 >> la4["b"]["n"][1]=[ruby]

la5=[map[a:map[b:golang] b:map[a:javascript d:ruby]]]
 >> la5["b"]["d"]=[ruby]

la6=[map[8:map[n:[ruby]] 2:map[b:[javascript scala golang]]]]
 >> la6[2]["b"]=[[javascript scala golang]]
 >> la6[8]["n"]=[[javascript scala golang]]
 >> la6[8]["n"][0]=[ruby]

la7=[map[2:map[3:[javascript scala golang]] 8:map[5:[javascript ruby node.js]]]]
 >> la7[2][3]=[[javascript scala golang]]
 >> la7[2][3][0]=[javascript]
 >> la7[8][5][2]=[node.js]

```

# 構造体：Struct
構造体をArrayでまとめる

```bash:b.go
package main

import (
    "fmt"
)

func main() {
    type Animal struct {
        Name string
        Age int
    }

    all_zoo :=[][]Animal{}
    zoo := []Animal{}

    zoo = append(zoo, Animal{Name:"CAT000",   Age:10})
    zoo = append(zoo, Animal{Name:"DOG000",   Age:4})
    zoo = append(zoo, Animal{Name:"Elep000",  Age:3})
    zoo = append(zoo, Animal{Name:"HORSE000", Age:2})
    zoo = append(zoo, Animal{Name:"DUCK000",  Age:1})

    all_zoo = append(all_zoo, zoo)
    all_zoo = append(all_zoo, zoo)


    for i:=0; i<len(all_zoo); i++ {
        for j:=0; j<len(zoo); j++ {
            fmt.Printf("[%d  %d : %s %d]\n", i, j, all_zoo[i][j].Name, all_zoo[i][j].Age)
        }
    }
}
```


# Reference

- [Goで二次元配列の初期化を一行で行う - Qiita](https://qiita.com/r9y9/items/362b4029b05cbca2cc70)
- [Goで多重連想配列 - Qiita] (https://qiita.com/daigo2010/items/d46975ad6decd8578c45)
- [Go言語の基本 — array と slice の違い - Qiita](https://qiita.com/YumaInaura/items/aec7857518102ff5e27c)
- [Go言語: いろいろなマップの作り方まとめ - Qiita](https://qiita.com/suin/items/7225ab9f2aeb6f55c606)