#安装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
06-14
360
08-08
1986