I'm developing a simple plugin system for a web application so that the handler could be loaded and set to a particular path at application startup time. When I use handler with known type, both by the main web app and the module library, everything work as expected. For example when using func(echo.Context) error as the handler signature (I'm using echo labstack framework).
But when I use function signature with empty interface to cater more dynamic client needs such as func(interface{}) (interface{}, int, error), the type conversion is not working.
Can we type cast a specific type (which is loaded from a library) to a more generic type? Or maybe there are other ways to accomplish this?
p, err := plugin.Open(libname)
sym, err := p.Lookup(handlerName)
handler, ok := sym.(func(interface{}) (interface{}, int, error))
Error Message -> invalid type assertion: sym.() (non-interface type func(main.HelloConfig) (interface{}, int, error) on left)