Data Base/Go
[์ฝ๊ณ ๋น ๋ฅธ Go ์์ํ๊ธฐ] #2.0 Account + NewAccount
์ฝ๋ฉํ๋ ๋ถ์ด
2021. 11. 2. 10:56
๋ฐ์ํ
๋ถ์ : GO์์ constructor์ ๋ง๋๋ ๋ฒ
accounts/accounts.go
package accounts
// Account struct
type Account struct {
owner string
balance int
}
// NewAccount creates Account
func NewAccount(owner string) *Account {
account := Account{owner: owner, balance: 0}
return &account
}
main.go
package main
import (
"fmt"
"github.com/serranoarevalo/learngo/accounts"
)
func main() {
account := accounts.NewAccount("nico")
fmt.Println(account)
}
&๊ฐ ๋ถ์ด์๋ ๊ฒ์ nico๊ฐ ๋ณต์ฌ๋ณธ์ด ์๋๋ผ object๋ผ๋ ๋ป์ด๋ค.
๋ฐ์ํ