dubbo-go
dubbo-go copied to clipboard
how to implement the Java Overload method in dubbogo
// java
public class CommentServiceImpl implements CommentService {
public boolean isForbidsSpeak(Long bookId, Long userId);
public boolean isForbidsSpeak(Long bookId, Long userId, String ip);
......
}
// go
type CommentServiceProvider struct{}
func (p *CommentServiceProvider) IsForbidsSpeak(ctx context.Context, params []interface{}) (interface{}, error) {
l := len(params)
if l == 2 {
// TODO
} else if l == 3 {
// TODO
} else {
// TODO
}
return nil, nil
}
func (p *CommentServiceProvider) MethodMapper() map[string]string {
return map[string]string{
"IsForbidsSpeak": "isForbidsSpeak",
}
}
更严谨点,就是判断下参数类型序列,但一般情况下没必要,毕竟 Go 的反射太费 cpu。
nice!
建议写个小工具做预处理和分发,减少代码复杂度
It should be Overload, not Override.
It should be Overload, not Override.
have changed the title. thx.