Tuesday, 20 August 2013

How to pass a struct to another package?

How to pass a struct to another package?

This is a very watered down version of what I'm trying to do but please
help me with the following scenario:
PackageA.go
package A
import "B"
type TestStruct struct {
Atest string
}
func Test() {
test := TestStruct{"Hello World"}
B.Test(test)
}
PackageB.go
package B
import "fmt"
func Test(test TestStruct) {
fmt.Println(test.Atest)
}
This fails with undefined: test when it hits Package B
Basically I'm having issues passing structs from one package to another or
even passing variables that act as pointers to other structs or functions.
Any pointers would be very helpful.

No comments:

Post a Comment