Skip to content

Commit 4b9f6f2

Browse files
committed
✨ (bitcoin-wallet): type alias with Bitcoin
1 parent af77a92 commit 4b9f6f2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package pointers_and_errors
22

3+
type Bitcoin int
34
type Wallet struct {
4-
balance int
5+
balance Bitcoin
56
}
67

7-
func (w *Wallet) Deposit(amount int) {
8+
func (w *Wallet) Deposit(amount Bitcoin) {
89
w.balance += amount
910
}
1011

11-
func (w *Wallet) Balance() int {
12+
func (w *Wallet) Balance() Bitcoin {
1213
return w.balance
1314
}

pointers-and-errors/bitcoin-and-wallet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ func TestWallet(t *testing.T) {
88

99
wallet.Deposit(10)
1010
got := wallet.Balance()
11-
want := 10
11+
want := Bitcoin(10)
1212
if got != want {
1313
t.Errorf("got %d, want %d", got, want)
1414
}

0 commit comments

Comments
 (0)