1 Star 1 Fork 5

infraboard / go-share-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 823 Bytes
一键复制 编辑 原始数据 按行查看 历史
Mr.Yu 提交于 2021-12-06 23:55 . rpc plus
package main
import (
"fmt"
"log"
"net/rpc"
"gitee.com/infraboard/go-share-examples/rpc-plus/service"
)
// 约束客户端
var _ service.HelloService = (*HelloServiceClient)(nil)
type HelloServiceClient struct {
*rpc.Client
}
func DialHelloService(network, address string) (*HelloServiceClient, error) {
c, err := rpc.Dial(network, address)
if err != nil {
return nil, err
}
return &HelloServiceClient{Client: c}, nil
}
func (p *HelloServiceClient) Hello(request string, reply *string) error {
return p.Client.Call(service.HelloServiceName+".Hello", request, reply)
}
func main() {
client, err := DialHelloService("tcp", "localhost:1234")
if err != nil {
log.Fatal("dialing:", err)
}
var reply string
err = client.Hello("hello", &reply)
if err != nil {
log.Fatal(err)
}
fmt.Println(reply)
}
Go
1
https://gitee.com/infraboard/go-share-examples.git
git@gitee.com:infraboard/go-share-examples.git
infraboard
go-share-examples
go-share-examples
f243a2248fe7

搜索帮助