From 97742e6172d700afb273e05c6167939f2a46aa98 Mon Sep 17 00:00:00 2001 From: asandikci Date: Mon, 24 Jul 2023 10:47:36 +0300 Subject: [PATCH] add methods from another package --- simple-structure/package-str/example/main.go | 8 ++++++++ simple-structure/package-str/great/great.go | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/simple-structure/package-str/example/main.go b/simple-structure/package-str/example/main.go index 6f1ba55..574d6b2 100644 --- a/simple-structure/package-str/example/main.go +++ b/simple-structure/package-str/example/main.go @@ -24,4 +24,12 @@ func main() { car3_1.Name = "ford" // car3_1.color = "green" // undefined fmt.Println(car3_1) + + fmt.Printf("\n\n") + + // car1.reset() // also functions/methods cannot be used outside of package itself + + car1.Reset2() // works + fmt.Println(car1) + } diff --git a/simple-structure/package-str/great/great.go b/simple-structure/package-str/great/great.go index a910195..8310e5c 100644 --- a/simple-structure/package-str/great/great.go +++ b/simple-structure/package-str/great/great.go @@ -32,6 +32,16 @@ func (c Car3) String() string { return fmt.Sprintf("car color:%q | name:%q", c.color, c.Name) } +func (c *Car) reset() { + c.Name = "" + c.Color = "" +} + +func (c *Car) Reset2() { + c.Name = "" + c.Color = "" +} + func Hello() { fmt.Println("Hello World (go-organization/simple-structure/package-str/great/great.go)") }