A RPC server and client using Thrift in Golang.
go test -v
./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
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电商网站
正常显示 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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。