16 Star 69 Fork 55

ShirDon-廖显东/Go语言高级开发与实战-随书代码

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
rpcCall.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2021-12-28 09:45 +08:00 . commit
//++++++++++++++++++++++++++++++++++++++++
// 《Go语言高级开发与实战》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// 知乎:https://www.zhihu.com/people/shirdonl
// 公众号:源码大数据
// 仓库地址:https://gitee.com/shirdonl/goAdvanced
// 仓库地址:https://github.com/shirdonl/goAdvanced
//++++++++++++++++++++++++++++++++++++++++
package distribute
import (
"fmt"
"net/rpc"
)
//定义RPC参数
type DoJobArgs struct {
JobType string
Urls []string
}
//定义RPC调用返回结果
type DoJobReply struct {
OK bool
}
//定义RPC注册参数
type RegisterArgs struct {
Worker string
}
//定义RPC注册返回参数
type RegisterReply struct {
OK bool
}
//定义RPC调用方法
func call(srv string, rpcName string,
args interface{}, reply interface{}) bool {
c, err := rpc.DialHTTP("tcp", srv)
if err != nil {
return false
}
defer c.Close()
err = c.Call(rpcName, args, reply)
if err == nil {
return true
}
fmt.Println(err)
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAdvanced.git
git@gitee.com:shirdonl/goAdvanced.git
shirdonl
goAdvanced
Go语言高级开发与实战-随书代码
0f051d9f4e35

搜索帮助