MacOS Go开发环境配置
Willem97 · · 1254 次点击 · · 开始浏览MacOS Go开发环境配置
Homebrew
安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"脚本很可能会停在
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...具体的解决方法可以参考:
https://juejin.im/post/6844903782589923335
之后下载go make等工具时,会出现下载龟速的情况,因为homebrew默认的是国外的源,下载的很慢,所以需要更换源为国内的
# 替换brew.git:
$ cd "$(brew --repo)"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-bottles:
# 中国科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 清华大学:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 应用生效:
$ brew update
Go安装
可以直接通过brew命令工具安装,或者在golang官网下载安装。
brew install go
.bash_profile
##brew更换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
###golang env
#golang proxy
export GOPROXY=https://mirrors.aliyun.com/goproxy/
#GOPATH
export GOPATH=$HOME/golang-project
#protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin`
#go mod
export GO111MODULE=onprotobuf相关安装
主要有
protocprotoc-gen-goprotoc-gen-grpc-gatewayprotoc-gen-swagger
安装方法如下:
brew install protoc
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go install github.com/golang/protobuf/protoc-gen-go安装后protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger的路径是$GOPATH/bin,需要将它们加入到PATH中,比如加入到.bash_profile中,添加下面这行
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin使用示例:
根据proto生成pb代码,网关api代码,swagger文档
protoc使用方法:protoc -h
生成stub, gw, swagge文档:https://github.com/grpc-ecosystem/grpc-gateway
#!/bin/bash
set -e
set -x
GEN_PATH=./
PROTOS=`find . -name "*.proto" | awk -F './' '{print 2ドル}'`
echo ${PROTOS}
for i in ${PROTOS}; do
echo $i;
#生成platform.pb.go
protoc -I/usr/local/include --proto_path=$GOPATH/src:. --proto_path=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc,paths=source_relative,:${GEN_PATH} $i;
#生成platform.pb.gw.go, platform.swagger.json
protoc -I/usr/local/include --proto_path=$GOPATH/src:. --proto_path=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:. --grpc-gateway_out=logtostderr=true:${GEN_PATH} $i;
done
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
关注微信- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码` - 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传
收入到我管理的专栏 新建专栏
MacOS Go开发环境配置
Homebrew
安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"脚本很可能会停在
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...具体的解决方法可以参考:
https://juejin.im/post/6844903782589923335
之后下载go make等工具时,会出现下载龟速的情况,因为homebrew默认的是国外的源,下载的很慢,所以需要更换源为国内的
# 替换brew.git:
$ cd "$(brew --repo)"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
# 替换homebrew-core.git:
$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
# 中国科大:
$ git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
# 清华大学:
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
# 替换homebrew-bottles:
# 中国科大:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 清华大学:
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
$ source ~/.bash_profile
# 应用生效:
$ brew update
Go安装
可以直接通过brew命令工具安装,或者在golang官网下载安装。
brew install go
.bash_profile
##brew更换
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
###golang env
#golang proxy
export GOPROXY=https://mirrors.aliyun.com/goproxy/
#GOPATH
export GOPATH=$HOME/golang-project
#protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin`
#go mod
export GO111MODULE=onprotobuf相关安装
主要有
protocprotoc-gen-goprotoc-gen-grpc-gatewayprotoc-gen-swagger
安装方法如下:
brew install protoc
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go install github.com/golang/protobuf/protoc-gen-go安装后protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger的路径是$GOPATH/bin,需要将它们加入到PATH中,比如加入到.bash_profile中,添加下面这行
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin使用示例:
根据proto生成pb代码,网关api代码,swagger文档
protoc使用方法:protoc -h
生成stub, gw, swagge文档:https://github.com/grpc-ecosystem/grpc-gateway
#!/bin/bash
set -e
set -x
GEN_PATH=./
PROTOS=`find . -name "*.proto" | awk -F './' '{print 2ドル}'`
echo ${PROTOS}
for i in ${PROTOS}; do
echo $i;
#生成platform.pb.go
protoc -I/usr/local/include --proto_path=$GOPATH/src:. --proto_path=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc,paths=source_relative,:${GEN_PATH} $i;
#生成platform.pb.gw.go, platform.swagger.json
protoc -I/usr/local/include --proto_path=$GOPATH/src:. --proto_path=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:. --grpc-gateway_out=logtostderr=true:${GEN_PATH} $i;
done