首页 > IT职业 > IT职场 > thrift 服务代理搭建
其实不建议使用 tcp 进行代理,因为太简单了
流量控制及请求来源限制
thrift_ gen.thnift thrift 配置文件thrift_ gen.thnift thrift 配置文件pratise/proxy/thrift_server_client/thrift_ gen.thnift
namespace go thrift_gen
struct Data {
1: string text
}
service format_data {
Data do_format(1:Data data),
}
进入目录 pratise/proxy/thrift_server_client 执行 模板代码生成命令 thrift --gen go thrift_gen.thrift
/d/Dev/env/thrift014/thrift014.exe --gen go thrift_gen.thnift
然后就会生成目录: pratise/proxy/thrift_server_client/gen-go
thrift 命令版本,与golang 项目安装版本需要保持一致。
否则生成代码可能报错
查看版本方法
$ /d/Dev/env/thrift014/thrift011.exe --version
Thrift version 0.14.2
客户端代码:pratise/proxy/thrift_server_client/thriftclient_main/main.go
服务端代码:pratise/proxy/thrift_server_client/thriftserver_main/main.go
启动 服务端代码:pratise/proxy/thrift_server_client/thriftserver_main/main.go
启动 客户端代码:pratise/proxy/thrift_server_client/thriftclient_main/main.go
处理方法:自己把 thrift 0.11.0 版本代码下载下来。自己发布一个 go module
# 启动服务器
go run thriftserver_v1/main.go
# 启动 客户端
go run thriftclient_v1/main.go
拷贝:D:Devenvgolangbinpkgmodgit.apache.orgthrift.git@v0.14.2tutorialgosrc
main true 运行 服务端
接下来,打开另一个terminal,把main函数里的server那里按上一节说的改成false,再运行,就是客户端了。
Administrator@DESKTOP-U15QB8I MINGW64 /d/Dev/workplace/golang/gateway_v1/pratise/proxy/thrift_server_client/thrift_v1 (master)
$ go run main.go server.go client.go handler.go
handler.go:25:2: package shared is not in GOROOT (D:Devenvgolangsrcshared)
server.go:26:2: package tutorial is not in GOROOT (D:Devenvgolangsrctutorial)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/381/viewspace-2796743/ ,如需转载,请注明出处,否则将追究法律责任。