Golang

mod 模式

模块名应带上地址,如:github.com/rabbee/leetcode。若地址不能通过https访问,模块名后需要加上后缀.git

1. 通过 go env 设置环境变量

# 设置代理
go env -w GOPROXY="https://goproxy.cn,direct"

# 设置私有库 (可选)
export PRIVATE_LIB="git.rabbee.cn"
go env -w GOPRIVATE=$PRIVATE_LIB
# 强制Git使用ssh而不是https访问私有库(当你的私有库无法通过https访问的时候启用)
git config --global url."git@$PRIVATE_LIB:".insteadOf "https://$PRIVATE_LIB/"

2. 初始化一个新的 go mod 项目

# 新建目录
mkdir project1 && cd project1
# 新建go.mod文件
go mod init {模块名}
# 编写代码后,运行tidy命令
go mod tidy

3. 迁移一个 GOPATH 项目

# 新建go.mod文件
go mod init {模块名}
# 下载项目依赖并生成相关文件
go mod tidy
# 下载项目依赖并生成vendor目录
go mod vendor

Rust

rustup

设置镜像源,windows用户在环境变量中设置RUSTUP_DIST_SERVER

RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

安装

rustup install stable

cargo

~/.cargo/config 文件中增加以下内容(cargo version >= 0.13)

[source.crates-io]
replace-with = 'tuna'

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"