On Jun 20, 2017 2:03 PM, "Dat Huynh" <audathu...@gmail.com> wrote:
Hi Ian, The struct instance I create for an interface will actually take the role of transport layer. I will not implement the real logic of the methods of the interface in client side. The real implementation for the logic of the methods will be implemented on the server side only. In the implementation of the methods for the struct instance, I write code to send interface name, method name and parameters to the server via my own protocol (e.g HTTP). Then it also receives and returns results to the place where we call methods. After we have such a library, we can use it with any interfaces and any methods, client side and server side will talk each other in our own protocol. You can encrypt data, compress data and do whatever with the data before you transfer it. Programers in client side just need to know which interface they want to use and they just use the library "servicefactory" to create a struct instance and use it to talk to the server. Before that, they must specify the IP to tell where the server is. I have successfully implemented the idea in Java and used it in my system with hundreds of interfaces. I wonder why I cannot do it in Go easily as what I did with Java. If I understand you correctly, the feature you are asking about--the one mentioned in the comment you pointed out in the original message--won't help you. The feature you want is a different one: to use the reflect package to define a new named type with a set of methods that you name and provide. That said, I agree that in Go this problem is normally solved by code generation. For example, protobufs. When that is not appropriate, most people use a purely dynamic approach, such as passing the method name as a string and doing runtime type checking, rather than hiding a dynamic approach via the reflect package. It's true that Java, which is a more dynamic language than Go, allows other approaches. Ian -- 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.