๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

go22

[Golang] go module error go.mod ํŒŒ์ผ์— ERROR๊ฐ€ ๋‚  ๋•Œ๊ฐ€ ์žˆ๋‹ค. ๊ทธ๋Ÿด๋• Terminal์— ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค. $ go mod init [module ๊ฒฝ๋กœ] $ go mod tidy 2021. 11. 17.
go: modules disabled by GO111MODULE=off; see 'go help modules' $ go mod tidy ๋ฅผ ํ„ฐ๋ฏธ๋„์— ์ž…๋ ฅํ•˜๋ฉด go: modules disabled by GO111MODULE=off; see 'go help modules' ๋ผ๋Š” ERROR๊ฐ€ ๋ฐœ์ƒํ•  ๋•Œ๊ฐ€ ์žˆ๋‹ค. ๋‹นํ™ฉํ•˜์ง€๋ง๊ณ  ์นจ์ฐฉํ•˜๊ฒŒ go env ๋ฅผ ํ•ด์ค€๋‹ค. $ go env off๊ฐ€ ๋˜์–ด ์žˆ์œผ๋ฉด on์œผ๋กœ ๋ฐ”๊ฟ”์ค˜์•ผํ•œ๋‹ค. ๋ฐ”๊ฟ”์ฃผ๋Š” ๋ฐฉ๋ฒ•์€ 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. 1. ํ„ฐ๋ฏธ๋„์— ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ๋‹ค. ๋‹จ์  : ์ผ์‹œ์ ์ผ ๊ฐ€๋Šฅ์„ฑ์ด ๋†’๋‹ค. ๋‚˜์ค‘์— ๋‹ค์‹œ off๋กœ ๋Œ์•„์˜ฌ ํ™•๋ฅ ์ด ๋†’์Œ $ export GO111MODULE="on" 2. nano ~/.zshrc ๋ฅผ ์‹คํ–‰ํ•ด์„œ vi Editor์—๋‹ค๊ฐ€ ๋„ฃ๋Š”๋‹ค. $ nano ~/.zshrc 2021. 11. 5.
[Golang] Map Literals ์ตœ์ƒ์œ„ ํƒ€์ž…์ด ํƒ€์ž… ์ด๋ฆ„์ผ ๊ฒฝ์šฐ, ๋ฆฌํ„ฐ๋Ÿด์˜ ์š”์†Œ์—์„œ ์ƒ๋žตํ•  ์ˆ˜ ์žˆ๋‹ค. - ๋ฆฌํ„ฐ๋Ÿด์ด ์ƒ๋žต๋˜์ง€ ์•Š์€ ๊ฒฝ์šฐ 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}, .. 2021. 11. 2.
[Golang] Maps map์€ ํ‚ค๋ฅผ ๊ฐ’์— ๋งคํ•‘ํ•œ๋‹ค. map์˜ zero value๋Š” nil์ด๋‹ค. nil map์€ ํ‚ค๋„ ์—†๊ณ , ํ‚ค๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜๋„ ์—†๋‹ค. make ํ•จ์ˆ˜๋Š” ์ฃผ์–ด์ง„ ํƒ€์ž…์ด ์ดˆ๊ธฐํ™”๋˜๊ณ  ์‚ฌ์šฉ ์ค€๋น„๊ฐ€ ๋œ map์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค. [์ฐธ๊ณ  ์‚ฌ์ดํŠธ - a Tour of Go] 2021. 11. 2.
[Golang] range // ์ผ๋ฐ˜์ ์ธ for๋ฌธ for i := 0; i < len(pow); i++ { v := pow[i] fmt.Printf("%d %d\n", i, v) } // range๋ฅผ ์‚ฌ์šฉํ•œ ๊ตฌ๋ฌธ for i, v := range pow { fmt.Printf("%d %d\n", i, v) } [์ฐธ๊ณ  ์‚ฌ์ดํŠธ - a Tour of Go] 2021. 11. 2.
[์‰ฝ๊ณ  ๋น ๋ฅธ Go ์‹œ์ž‘ํ•˜๊ธฐ] #2.2 Methods part Two [์ถœ์ฒ˜ - Nomad Coders] accounts/accounts.go package accounts import "errors" // Account struct type Account struct { owner string balance int } var errNoMoney = errors.New("Can't withdraw") // NewAccount creates Account func NewAccount(owner string) *Account { account := Account{owner: owner, balance: 0} return &account } // Deposit x amount on your account func (a *Account) Deposit(amount int) { a.. 2021. 11. 2.
๋ฐ˜์‘ํ˜•