๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Data Base/Go

[Golang] Map Literals

by ์ฝ”๋”ฉํ•˜๋Š” ๋ถ•์–ด 2021. 11. 2.
๋ฐ˜์‘ํ˜•

์ตœ์ƒ์œ„ ํƒ€์ž…์ด ํƒ€์ž… ์ด๋ฆ„์ผ ๊ฒฝ์šฐ, ๋ฆฌํ„ฐ๋Ÿด์˜ ์š”์†Œ์—์„œ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

 

- ๋ฆฌํ„ฐ๋Ÿด์ด ์ƒ๋žต๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ

type Vertex struct {
	Lat, Long float64
}

// ๋ฆฌํ„ฐ๋Ÿด์ด ์ƒ๋žต๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ
var m = map[string]Vertex{
	"Bell Labs": Vertex{
		40.68433, -74.39967,
	},
	"Google": Vertex{
		37.42202, -122.08408,
	},
}

func main() {
	fmt.Println(m)
}

 

 

 

- ๋ฆฌํ„ฐ๋Ÿด์ด ์ƒ๋žต๋œ ๊ฒฝ์šฐ

type Vertex struct {
	Lat, Long float64
}

// ๋ฆฌํ„ฐ๋Ÿด์ด ์ƒ๋žต๋œ ๊ฒฝ์šฐ
var m = map[string]Vertex{
	"Bell Labs": {40.68433, -74.39967},
	"Google":    {37.42202, -122.08408},
}

func main() {
	fmt.Println(m)
}
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€