From 8bff3c7f290d6960531e90943be5fc3d7bcecb68 Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Mon, 3 Jun 2024 23:52:19 +0800 Subject: [PATCH 1/3] Create people.go --- practise/interface-practise/people.go | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 practise/interface-practise/people.go diff --git a/practise/interface-practise/people.go b/practise/interface-practise/people.go new file mode 100644 index 0000000..813da77 --- /dev/null +++ b/practise/interface-practise/people.go @@ -0,0 +1,56 @@ +package main + +import "fmt" + +type People interface { + GetName() string + GetAge() int + + GetData() people +} + +type people struct { + name string +} + +func (p people) GetName() string { + return p.name +} + +func (p people) GetData() people { + return p +} + +func NewPeople(name string) people { + return people{ + name: name, + } +} + +type Ming struct { + people + age int +} + +func (x Ming) GetAge() int { + return x.age +} + +//func (x Ming) GetName() string { +// return "daming" +//} + +func NewMing() People { + return Ming{ + people: NewPeople("xiaoming"), + age: 18, + } +} + +func main() { + m := NewMing() + + fmt.Println(m.GetAge()) + fmt.Println(m.GetName()) + fmt.Println(m.GetData()) +} From bb9a5d6facd3bdb87bfb0b5c26171fa156e3b998 Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Mon, 3 Jun 2024 23:56:28 +0800 Subject: [PATCH 2/3] add --- practise/interface-practise/people.go | 40 +++++++++++++-------------- t1.go | 15 ++++++++++ 2 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 t1.go diff --git a/practise/interface-practise/people.go b/practise/interface-practise/people.go index 813da77..d38139f 100644 --- a/practise/interface-practise/people.go +++ b/practise/interface-practise/people.go @@ -3,37 +3,37 @@ package main import "fmt" type People interface { - GetName() string - GetAge() int + GetName() string + GetAge() int - GetData() people + GetData() people } type people struct { - name string + name string } func (p people) GetName() string { - return p.name + return p.name } func (p people) GetData() people { - return p + return p } func NewPeople(name string) people { - return people{ - name: name, - } + return people{ + name: name, + } } type Ming struct { - people - age int + people + age int } func (x Ming) GetAge() int { - return x.age + return x.age } //func (x Ming) GetName() string { @@ -41,16 +41,16 @@ func (x Ming) GetAge() int { //} func NewMing() People { - return Ming{ - people: NewPeople("xiaoming"), - age: 18, - } + return Ming{ + people: NewPeople("xiaoming"), + age: 18, + } } func main() { - m := NewMing() + m := NewMing() - fmt.Println(m.GetAge()) - fmt.Println(m.GetName()) - fmt.Println(m.GetData()) + fmt.Println(m.GetAge()) + fmt.Println(m.GetName()) + fmt.Println(m.GetData()) } diff --git a/t1.go b/t1.go new file mode 100644 index 0000000..e3e2756 --- /dev/null +++ b/t1.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + "strings" +) + +func main() { + fmt.Println("ddd") + eventFS := make([]string, 0) + + fmt.Println(eventFS) + fs := strings.Join(eventFS, ",") + fmt.Println("ddd", fs, len(fs)) +} From 481c1f2d968cb95746692b7dd330d6d7ca886d53 Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Mon, 3 Jun 2024 23:57:00 +0800 Subject: [PATCH 3/3] add --- t1.go | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 t1.go diff --git a/t1.go b/t1.go deleted file mode 100644 index e3e2756..0000000 --- a/t1.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "fmt" - "strings" -) - -func main() { - fmt.Println("ddd") - eventFS := make([]string, 0) - - fmt.Println(eventFS) - fs := strings.Join(eventFS, ",") - fmt.Println("ddd", fs, len(fs)) -}