diff --git a/tour-of-go/methods-2/main.go b/tour-of-go/methods-2/main.go index 1e63dd1..860dd77 100644 --- a/tour-of-go/methods-2/main.go +++ b/tour-of-go/methods-2/main.go @@ -2,17 +2,33 @@ package main import ( "fmt" + "time" ) -type Nums struct { - X float64 +type Person struct { + name string + country string } -func (n Nums) Multiply() float64 { - return n.X * 2 +type yearType int + +func (p Person) Create() (newP *Person) { + var newPerson = new(Person) + newPerson.name = "John" + newPerson.country = "Spain" + return newPerson +} + +func (y yearType) currentYear() (year yearType) { + t := time.Now() + ye := t.Year() + yea := yearType(ye) + return yea } func main() { - newnumber := Nums{10} - fmt.Println(newnumber.Multiply()) + p := Person{} + var ourYear yearType + newP := p.Create() + fmt.Printf("Hello, I am %s and live in %s and the current year is %d\n", newP.name, newP.country, ourYear.currentYear()) }