I have a function in a package which returns a slice of a specific struct I defined in my package, then I'm importing this package to another main package and I want to iterate over the slice returned from the function and access the structs fields, I'm getting "undefined" error.
"s.a undefined (cannot refer to unexported field or method a)"
What am I missing?
thanks for the help.
the packages code:
package test_package
import "fmt"
type Struct struct {
a string
b string
}
func ReturnStructSlice() ([]Struct){
s1 := Struct{"a", "b"}
s2 := Struct{"c", "d"}
structSliceToReturn := []Struct{s1, s2}
for _, s := range structSliceToReturn {
fmt.Println(" ", s.a)
}
return structSliceToReturn
}
this is the main package:
package main
import (
t "/test_package"
"fmt"
)
func main() {
sList := t.ReturnStructSlice()
for _, s := range sList {
fmt.Println(" ", s.a) \\ here I'm getting the error
}
}