github.com/goplus/gop@v1.2.6/printer/_testdata/26-Method/method.gop (about) 1 type Person struct { 2 Name string 3 Age int 4 Friends []string 5 } 6 7 func (p *Person) SetName(name string) { 8 p.Name = name 9 println(p.Name) 10 } 11 12 func (p *Person) SetAge(age int) { 13 age = age + 5 14 p.Age = age 15 println(p.Age) 16 } 17 18 func (p *Person) AddFriends(args ...string) { 19 p.Friends = append(p.Friends, args...) 20 } 21 22 type M int 23 24 func (m M) Foo() { 25 println("foo", m) 26 } 27 28 p := Person{ 29 Name: "bar", 30 Age: 30, 31 } 32 33 p.Name, p.Age = "bar2", 31 34 35 p.SetName("foo") 36 p.SetAge(32) 37 p.AddFriends("a", "b", "c") 38 39 a := int32(0) 40 m := M(a) 41 m.Foo() 42 43 println(p.Name) 44 println(p.Age) 45 println(p.Friends) 46 println(m)