Got a weird problem here. A app that i’m developing is based on plugins. In one of this plugins i return a struct that implements a interface defined at the application. The problem is, i can’t do a interface convertion with this object.
The compiler gives me this error: panic: interface conversion: *mongodb.Document is not flare.DocumentRepositorier: missing method FindOne. But if i print all the methods from the struct, it print this:
Delete
FindOne
FindOneWithRevision
Update
So, the FindOne is there, but it still don’t let me convert the struct. Anyone already got something similar?
func (c *config) documentRepository() (flare.DocumentRepositorier, error) {
obj := c.plugin.getObj("flare.DocumentRepositorier")
if obj == nil {
return nil, errors.New("don't found any plugin that implements the flare.DocumentRepositorier")
}
repo, ok := obj.(flare.DocumentRepositorier)
if !ok {
return nil, errors.New("could not cast the plugin obj to flare.DocumentRepositorier")
}
return repo, nil
}
# github.com/diegobernardes/flare/services/flare
../config.go:44:5: cannot use x (type *mongodb.Document) as type "github.com/diegobernardes/flare".DocumentRepositorier in assignment:
*mongodb.Document does not implement "github.com/diegobernardes/flare".DocumentRepositorier (wrong type for FindOne method)
have FindOne(context.Context, string) (*"github.com/diegobernardes/flare-mongodb/vendor/github.com/diegobernardes/flare".Document, error)
want FindOne(context.Context, string) (*"github.com/diegobernardes/flare".Document, error)