Skip to content

Instantly share code, notes, and snippets.

@petrjahoda
Created August 14, 2021 07:25
Show Gist options
  • Save petrjahoda/f982c8693466c0417d61351779ef2076 to your computer and use it in GitHub Desktop.
Save petrjahoda/f982c8693466c0417d61351779ef2076 to your computer and use it in GitHub Desktop.
2. Changing the name with a function, by passing the value
package main
import "fmt"
type Car struct {
name string
}
type Truck struct {
name string
}
func main() {
bmw := Car{name: "bmw is the best car"}
volvo := Truck{name: "volvo is the best truck"}
bmw.name = changeNameOfCar(bmw)
volvo.name = changeNameOfTruck(volvo)
fmt.Println(bmw.name)
fmt.Println(volvo.name)
}
func changeNameOfCar(c Car) string {
return c.name + "\n\t... changed with simple function"
}
func changeNameOfTruck(t Truck) string {
return t.name + "\n\t... changed with simple function"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment