centos7 golang环境搭建

3 篇文章 0 订阅
#安装golang
wget https://studygolang.com/dl/golang/go1.14.13.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.14.13.linux-amd64.tar.gz 
mkdir -p /home/kkkwant/go/bin /home/kkkwant/go/pkg /home/kkkwant/go/src

vi /etc/profile #在最下面添加
export GOROOT=/usr/local/go
export GOPATH=/home/kkkwant/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
source /etc/profile #可重启生效
go version
go env

#配置mod
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct

#安装protobuf
yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++
cd  /home/go
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protobuf-all-3.14.0.zip
unzip protobuf-all-3.14.0.zip
cd protobuf-3.14.0
./configure
make
make install
protoc -v

#安装micro完, 查gopath/bin下 有micro  protoc-gen-go  protoc-gen-micro
go get github.com/micro/go-micro
go get github.com/golang/protobuf/{proto,protoc-gen-go}
go get github.com/micro/protoc-gen-micro
go get github.com/micro/micro
micro -v 

 vim hello.proto 测试protobuf,micro
syntax = "proto3";
package hello;
service Hello {
  rpc List (HelloReq) returns (HelloRsp) {}
}
message HelloReq {
  string name = 1;
}
message HelloRsp {
  string message = 1;
}
protoc --proto_path=. --go_out=. --micro_out=. hello.proto

micro new --type "web" day/micro/rpc/web
micro new --type "srv" day/micro/rpc/srv

#如micro服务发现用etcd, 查服务列表
micro --registry=etcd --registry_address=x.x.x.x web
micro --registry=etcd --registry_address=x.x.x.x list services
micro --registry=etcd call go.micro.srv.srv Hello.List '{"name":"ming"}'

 代码可视化插件
git clone https://github.com/TrueFurby/go-callvis.git
cd go-callvis && make install
测试可视化
git clone https://github.com/gusibi/oneplus.git
cd oneplus/idgenerator/src
go-callvis  -group pkg,type md52id # md52id 是package name
go-callvis -focus=md52id/idg -group pkg,type -limit md52id md52id #只看idg的
http://127.0.0.1:7878  


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值