1 Star 0 Fork 0

walter / thrift_tutorial_go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Thrift的灵感来源于pillar, 一款由Adam D’Angelo编写的轻量级RPC工具, 同时也借鉴了Google的protocol buffers。

A RPC server and client using Thrift in Golang.

Requirements

Tests

go test -v

介绍

《Apache Thrift官方文档》简介

安装教程

./go-tutorial -server=true -secure=true ./go-tutorial -secure=true

GO = /usr/local/bin/go ~/thrift/tutorial/go   master ●  make check ~/thrift/tutorial/go   master ●  ./go-tutorial -server=true *thrift.TServerSocket Starting the simple server... on localhost:9090 ping() add(1,1) calculate(1, {DIVIDE,1,0}) calculate(1, {SUBTRACT,15,10}) getStruct(1)

~/thrift/tutorial/go   master ●  ./go-tutorial ping() 1+1=2 Invalid operation: InvalidOperation({WhatOp:4 Why:Cannot divide by 0}) 15-10=5 Check log: 5

export GO111MODULE=auto export GOPATH=~/GolandProjects/thrift_tutorial_go/tutorial/go/ make check

to create a module there, run: cd ../.. && go mod init

'go mod init example.com/m' to initialize a v0 or v1 module 'go mod init example.com/m/v2' to initialize a v2 module

~/GolandProjects/thrift_tutorial_go   master ●✚  go run main.go
Starting the simple server... on localhost:9090

export GOPROXY=https://goproxy.cn export GOPATH=~/GolandProjects/thrift_tutorial_go/IDL go build EchoServerImp.go go build EchoClient.go

生成go代码:thrift -o <output directory{默认当前目录gen-py}> -gen go {对应版本的hbase源码地址}\src\main\resources\org\apache\Hadoop\hbase\thrift2 将对应版本中golang接口code复制到当前golang安装目录,{$GOROOT}\src或者{$GOPATH}\src… 再通过git获取外部资源git.apache.org/thrift.git/lib/go/thrift : go get git.apache.org/thrift.git/lib/go/thrift 或者直接到 https://github.com/apache/thrift 直接下载zip包,将至放在$GPPATH\src\git.apache.org\thrift.git\ 目录下即可。 GOPATH="/Users/wolingzong/go" export GOPATH=/GolandProjects/thrift_tutorial_go/tutorial/go/:/GolandProjects/thrift_tutorial_go/IDL export GOROOT=~/GolandProjects/thrift_tutorial_go/

export CGO_ENABLED=0 go test -v

什么时候要选择使用 Thrift 1.高并发

2.请求和响应的数据传输量大

3.业务系统跨多种语言

thrift -version

 -->>> Thrift version 0.14.0

IDE插件 *1、JetBrains PhpStorm 可以在插件里找到Thrift Support安装,重启IDE后就支持Thrift格式语法了。 *2、VScode 在扩展里搜索 Thrift,安装即可。

编译

go install

一切顺利的话,这里就在 $GOPATH/bin/hbaseThriftTest 的可执行文件,记得把 $GOPATH/bin 加入到 $PATH 变量中

thrift --gen go timeRPC.thrift thrift -r --gen go tutorial.thrift thrift --gen go shared.thrift

thrift -r --gen go HelloThrift.thrift

brew info go
brew install go

go build  main.go server.go handler.go client.go
./main  -server=true 

~/thrift/tutorial/go/

https://github.com/apache/thrift/blob/master/tutorial/go/Makefile.am

首先我们初始化go mod: go mod init sample

首先是安装golang的库:

go get git.apache.org/thrift.git/lib/go/thrift/...

go get git.apache.org/thrift.git/lib/go/thrift thrift -gen go RpcService.thrift

go get github.com/apache/thrift/lib/go/thrift

go get git.apache.org/thrift.git/lib/go/thrift

go get github.com/apache/thrift/lib/go/thrift/... go install git.apache.org/thrift.git/lib/go/thrift go get git.apache.org/thrift.git/lib/go/thrift

"github.com/apache/thrift/lib/go/thrift"

##测试 go run server.go go test -v

export http_proxy=socks5://127.0.0.1:1086\nexport https_proxy=$http_proxy\nexport all_proxy=$http_proxy go get git.apache.org/thrift.git/lib/go/thrift

https://sookocheff.com/post/thrift/so-you-want-to-use-thrift/

go build main.go client.go handler.go server.go

✘  ~/GolandProjects/thrift_tutorial_go/thrift/tutorial_sample   master ●✚  ./main -server=true *thrift.TServerSocket Starting the simple server... on localhost:9090 ping() add(1,1) calculate(1, {DIVIDE,1,0}) calculate(1, {SUBTRACT,15,10}) getStruct(1)

✘  ~/GolandProjects/thrift_tutorial_go/thrift/tutorial_sample   master ●✚  ./main ping() 1+1=2 Invalid operation: InvalidOperation({WhatOp:4 Why:Cannot divide by 0}) 15-10=5 Check log: 5

1.最简单的go电商网站

访问 http://localhost:4040/

正常显示 Let's Shopping!

2.mysql访问

3.go的Cgo使用 下载win环境下gcc下载:TDM gcc,安装后会自动加入到PATH下,cmd里就能使用gcc命令。 http://downloads.sourceforge.net/project/tdm-gcc/TDM-GCC%20Installer/tdm-gcc-4.8.1-3.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Ftdm-gcc%2F&ts=1391271291&use_mirror=ncu

05.golang访问mongodb4.0 下载monggo驱动 git clone http://gopkg.in/mgo.v2 运行输出: G:/work/go/05_mongo/05_mongo.exe [G:/work/go/05_mongo] Name: superWang Phone: 13478808311 成功: 进程退出代码 0.

空文件

简介

thrift go教程 展开 收起
Go
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/walter80/thrift_tutorial_go.git
git@gitee.com:walter80/thrift_tutorial_go.git
walter80
thrift_tutorial_go
thrift_tutorial_go
master

搜索帮助