I have defined a
Type
type UnknownMapString
map[string]interface{}
I
also have methods for them like
so
func (m UnknownMapString) Foo()
{
fmt.Println("test!")
}
I
get a panic when running:
interface conversion: interface is map[string]interface {}, not
main.UnknownMapString
The
map[string]interface{} is unmarshaled from JSON
input.
Playground replicating it -> href="http://play.golang.org/p/kvw4dcZVNH"
rel="nofollow">http://play.golang.org/p/kvw4dcZVNH
I
thought that you could not have interface as a receiver of method so we needed to type
assert (not convert?) to a Named Type and use that Named Type as the receiver of the
method.
Please let me know what I'm doing wrong. Thanks!
No comments:
Post a Comment