micro微服务模块搭建
# 创建项目
使用官方给出的micro
的镜像创建项目
首先使用docker
拉取镜像
docker pull micro/micro
1
使用镜像创建模块
docker run --rm -v $(PWD):$(PWD) -w $(PWD) micro/micro new user
1
项目目录搭建
新建domain
目录,并创建 3 个子目录:model
、repository
、service
# Go module 使用
# 基本设置
- Go >= 1.13 会自动默认使用
Go Modules
- Go Modules 使用
GOPROXY
环境变量来解决无法使用go get
问题
# 私有仓库设置
- 使用
go env
查看本机参数 GOPRIVATE="*.github.com"
# Go module 加速设置
- GOPROXY="https://goproxy.io"
- 固化可以把命令写到
.bashrc或者.bash_profile
文件当中 - windows cmd 命令设置
set GOPROXY="https://goproxy.io"
# Go module 设置 github 私有仓库
生成 token
https://github.com/settings/tokens/new (opens new window)
将 token 设置到请求头中
git config --global http.extraheader "PRIVATE-TOKEN:YOUR_PRIVATE_TOKEN"
1
配置 git 将请求从 ssh 转换为 http
#全局替换拉取域下的所有包
git config --global url."git@github.com:xxxx".insteadOf "https://github.com/xxxx"
1
2
3
2
3
#全局替换拉取域下的单个包,使用“全局替换拉取域下的所有包” 可以不设置
git config --global url."git@github.com:xx/xxx.git".insteadOf "https://github.com/xx/xxx.git"
1
2
2
检查配置
cat ~/.gitconfig
[http]
extraheader = PRIVATE-TOKEN:xxxxx
[url "git@github.com:xxxxx"]
insteadOf = https://github.com/xxxx
1
2
3
4
5
2
3
4
5
使用go env
查看结果
测试配置结果
# 执行
go mod tidy
# 显示
go: finding module for package github.com/xxx
go: found github.com/xx/xxx/inits in github.com/xxx/xxx v1.0.1
# 那么就设置成功了
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
编辑 (opens new window)
上次更新: 2021/12/09, 23:18:36