go的rpc出现提示:method Xxx has wrong number of ins: 1
wk3368 · · 8286 次点击 · · 开始浏览the way to go的19ドル.8和19ドル.9里面的demo:goto_5
$go version
go version go1.1.2 darwin/amd64
$./goto_v5 -http=:8081 -rpc=true //启动master的时候,会显示下面一行提示:
2014年12月02日 22:36:29 method Count has wrong number of ins: 1func (s *URLStore) Put(url, key *string) error {
for {
*key = genKey(s.Count())
if err := s.Set(key, url); err == nil {
break
}
}
if s.save != nil {
s.save <- record{*key, *url}
}
return nil
}
func (s *URLStore) Count() int {
s.mu.RLock()
defer s.mu.RUnlock()
return len(s.urls)
}
出现这个提示的原因是:
1.RPC can only work through methods with the form (t is a value of type T):
func (t T) Name(args *ArgType, reply *ReplyType) error
2.Count()这个函数本来是私有的,但是错误的public了。而且函数的参数和返回类型跟RPC能处理的Public函数要求不一致。
goto_v1~goto_v4这4个版本没有加rpc的时候,没问题。
goto_v5用了rpc,就把这个问题暴露出来了。
解决办法:
把这两个地方的Count改成count,重新编译,运行就ok了!
参考: https://code.google.com/p/go/issues/detail?id=1056
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
the way to go的19ドル.8和19ドル.9里面的demo:goto_5
$go version
go version go1.1.2 darwin/amd64
$./goto_v5 -http=:8081 -rpc=true //启动master的时候,会显示下面一行提示:
2014年12月02日 22:36:29 method Count has wrong number of ins: 1func (s *URLStore) Put(url, key *string) error {
for {
*key = genKey(s.Count())
if err := s.Set(key, url); err == nil {
break
}
}
if s.save != nil {
s.save <- record{*key, *url}
}
return nil
}
func (s *URLStore) Count() int {
s.mu.RLock()
defer s.mu.RUnlock()
return len(s.urls)
}
出现这个提示的原因是:
1.RPC can only work through methods with the form (t is a value of type T):
func (t T) Name(args *ArgType, reply *ReplyType) error
2.Count()这个函数本来是私有的,但是错误的public了。而且函数的参数和返回类型跟RPC能处理的Public函数要求不一致。
goto_v1~goto_v4这4个版本没有加rpc的时候,没问题。
goto_v5用了rpc,就把这个问题暴露出来了。
解决办法:
把这两个地方的Count改成count,重新编译,运行就ok了!
参考: https://code.google.com/p/go/issues/detail?id=1056