I am attempting to create a type that represents a slice of pointers to another type and define a method for it, my code looks similar to this, albeit a bit simplified for the example:
package column
type Column struct {
name string
}
type Columns []*Column
func (c Column) ToString() string {
return c.name
}
func (c Columns) ToStrings() []string {
var strSlice []string
for _, v := range c {
strSlice = append(strSlice, v.ToString())
}
return strSlice
}
It is then called in a separate file like this:
import (
c "main/column"
"strings"
)
type Columns c.Columns
func ToString(col Columns) string {
return strings.Join(col.ToStrings(), ",
")
}
However when I try to call the method ToStrings()
on the exported "Columns" type I get this error:
columns.ToStrings undefined (type Columns has no field or method ToStrings)
It seems the compiler can't find the method ToStrings()
. Is there a way around this? Why can't the compiler find the exported method defined for the "Columns" type?