Hi,

What I want is to use interfaces to describe services for client side of my 
app.
Then, I implement the services on the server side and allow client side to 
call the services via my pre-defined protocol (e.g HTTP, ...)

In Java, I used the method newProxyInstance( ) of the class 
 java.lang.reflect.Proxy to implement the idea.
However, I don't know how to implement it easily in Go.

Below is what I expect to write in Go in client side.


type MyFooInterface interface {
  Method1() int
  Method2(a int, b int) string
   // any methods
}
func main() {
        servicefactory.Init("http://URL/transport";)

        var myService MyFooInterface

        // pass any interface and obtain a struct instance which implements 
the methods of the interface.
       //In java, I just write myservice = 
ServiceFactory.CreateService(MyFooInterface.class) 

        myService = servicefactory.CreateService((*MyFooInterface)(nil)).(
MyFooInterface) 
        myService.Method2(10, 20) 
}


Enter code here...

Thank you very much.

Regards,
Dat.





On Wednesday, June 14, 2017 at 4:28:59 PM UTC+10, Lutz Horn wrote:
>
> Hi, 
>
> > Given an interface, how can I create a struct instance with the 
> > methods of the interface at runtime? 
>
> What is your usecase for this? What problem are you trying to solve? 
>
> Lutz 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to