I have defined and created an instance of a struct in my main.go file. And I want to call a function from the functions/functions.go file using an instance of my struct as the parameter
package main
import (
"./functions"
)
type person struct {
name string
age int
}
func main() {
person1 := person{"James", 24}
functions.Hello(person1)
}
main.go
package functions
import "fmt"
type person struct {
name string
age int
}
func Hello(p person) {
fmt.Println(p.name, "is", p.age, "years old")
}
functions/functions.go
When I run this code with: go run main.go
, I get the error: main.go:16:17: cannot use person1 (type person) as type functions.person in argument to functions.Hello
My question
What is the correct way to pass an instance of a struct as parameter to an imported function in Go?