-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom.go
50 lines (40 loc) · 780 Bytes
/
custom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import "fmt"
type Updater interface {
UpdateQty(qty int, rounds int) int
}
type custom struct {
name string
qty int
legit bool
toys map[int]string
}
func (c *custom) UpdateQty(qty int, rounds int) int {
for i := 0; i < rounds; i++ {
c.qty = c.qty + qty
}
return c.qty
}
func (c custom) PrintName(greeting string) {
if len(c.name) != 0 {
fmt.Printf("%s %s ", greeting, c.name)
}
}
func main() {
c := &custom{
name: "Wheee",
qty: -33,
legit: false,
toys: map[int]string{1: "thiss", 2: "thatt"},
}
fmt.Printf("%s\n", c.name)
fmt.Printf("%d\n", c.qty)
fmt.Printf("%t\n", c.legit)
fmt.Printf("%#v\n", c.toys)
c.PrintName("Hello World!")
c.UpdateQty(111, 3)
var u Updater
u = c
u.UpdateQty(11, 8)
fmt.Printf("%v\n", c)
}