go get with git repository with http

go lang 的 go tools 做 go get 時,預設都會用 https 去存取 git repository,可是當 https 不能使用,只能跑 http 的時候,要做一些改變。

實際上 go get 指令也是透過 git command 去執行,只是會在 git repository 前面加上 https:// 去存取。例如:

$ go get GIT.URL/NAMESPACE/Repository.git

實際上會把 GIT.URL/NAMESPACE/Repository.git 加上 https:// 給 git 去處理,所以變成類似

$ git clone https://GIT.URL/NAMESPACE/Repository.git

所以如果 https 不能用,那就只能走 http。這時候就只好從 git config 下手,改走 ssh

git config --global url."git@GIT.URL:".insteadOf "https://GIT.URL/"

或者走 http

git config --global url."http://GIT.URL/".insteadOf "https://GIT.URL/"