Golang编程语言知识介绍


  • 首页

  • todo

  • 思考

  • life

  • food

  • OS

  • lua

  • redis

  • Golang

  • C

  • TCP/IP

  • ebpf

  • p4

  • OpenVPN

  • IPSec

  • L2TP

  • DNS

  • distributed

  • web

  • OpenWRT

  • 运维

  • Git

  • 鸟哥的私房菜

  • IT杂谈

  • 投资

  • About Me

  • 友情链接

  • FTP

  • 搜索
close

thrift 之 go 入门 Getting Started with Thrift Go

时间: 2023-12-08   |   分类: IT   rpc   thrift     |   阅读: 286 字 ~1分钟

下载、安装 thrift 编译器

  1. thrift 编译器的下载连接 https://thrift.apache.org/downloa 这里注意下版本
  2. 将下载的编译器放到系统的可执行目录下,并去掉版本信息, eg: thrift-0.19.0.exe 改为 thrift.exe

go 安装 thrift 包

go get github.com/apache/thrift@0.19.0
#这里的版本要和上面的对应

新建 tmp 目录

新建一个临时目录 tmp
在新建的 tmp 目录下新建一个存放 thrift 文件的 thrift 目录
将上述 thrift 包的实例文件(tutorial)拷贝到 thrift 目录下
我这里的 thrift 安装包的路径是 C:\Users\shanks\go\pkg\mod\github.com\apache\thrift@v0.19.0 
将 tutorial 中的 shared.thrift 和 tutorial.thrift 文件 拷贝到 tmp/thrift中

生成对应语言的协议文件

在上述新建的 tmp 目录下执行 
thrift -r --gen go thrift/tutorial.thrift
生产 go 语言版本的 thrift协议代码

拷贝实例代码

将上述安装目录下的 tutorial\go\src 中的代码(包括上层的 server.crt 和 server.key )拷贝到 tmp 目录下

编译 go 代码

go mod init example.com/m 有 go.mod 可不执行
go build main.go
编译报错处理即可
#IT# #rpc# #thrift#
golang使用gopacket包进行数据包捕获,注入和分析
go flags包简介 go flags package introduction
shankusu2017@gmail.com

shankusu2017@gmail.com

日志
分类
标签
GitHub
© 2009 - 2025
粤ICP备2021068940号-1 粤公网安备44011302003059
0%