我使用的是Gorilla XMLRPC。根据示例,
func (h *HelloService) Say(r *http.Request,
args *struct{Who string},
reply *struct{Message string}) error {
reply.Message = "Hello, " + args.Who + "!"
return nil
}RPC.RegisterService(new(HelloService), "")给了我一个服务HelloService.Say()。我想要helloService.say()。我可以通过将寄存器函数修改为RPC.RegisterService(new(HelloService), "helloService")来获得第一部分。但是我不能导出小写的方法。
我知道golang只允许导出大写的方法。那么有没有小写方法的变通方法呢?
发布于 2017-01-22 12:44:36
我今天遇到了同样的问题。这个问题是几年前在gorilla-xmlrpc中出现的solved。现在,您可以在xmlrpc编解码器上注册别名:
myCodec := xml.NewCodec()
myCodec.RegisterAlias("MyType.lowerCaseMethod", "MyType.UpperCaseMethod")使用例如<methodName>MyType.lowerCaseMethod</methodName>的输入将被识别为预期的。
此函数在godoc中有说明,但在项目自述文件或相关示例中未提及。
发布于 2015-04-09 10:40:01
我认为第一个问题是“为什么需要小写”,第二个问题是,如果需要这样做,为什么要使用Go?
按照惯例,导出大写的方法和属性,而小写的方法和属性是私有的。
https://stackoverflow.com/questions/29520593
复制相似问题