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

[์‰ฝ๊ณ  ๋น ๋ฅธ Go ์‹œ์ž‘ํ•˜๊ธฐ] #2.0 Account + NewAccount

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

๋ถ€์ œ : 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๋ผ๋Š” ๋œป์ด๋‹ค.

 

 

 

 

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€