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