go get golang.org被牆問題解決
今天在下載golang.org/x/image/tiff的時候出錯
> go get -v golang.org/x/image/tiff
Fetching https://golang.org/x/image/tiff?go-get=1
https fetch failed: Get https://golang.org/x/image/tiff?go-get=1: dial tcp 216.239.37.1:443: i/o timeout
package golang.org/x/image/tiff: unrecognized import path "golang.org/x/image/tiff" (https fetch: Get https://golang.org/x/image/tiff?go-get=1: dial tcp 216.239.37.1:443: i/o timeout)
網上看了一下,大致是由於牆的問題。
網上的方式大致有兩種,一種是使用golang.org在github上的鏡像,比如https://github.com/golang/image
在gopath目錄下手動創建src/golang.org/x/, 然后直接使用git clone https://github.com/golang/image
到 src/golang.org/x/image目錄
但是由於我最終希望下的是qor項目,它依賴非常多的golang.org/x/的項目,一個個這么做也是夠累人的。
於是選擇了第二個方法,設置proxy。
設置session的http_proxy
翻牆軟件搭建在自己機器上, 使用端口61745, 先設置當前session使用的http_proxy
export http_proxy="http://127.0.0.1:61745" export https_proxy=$http_proxy
設置完成之后,但是還是出現問題:
go get -v golang.org/x/image/tiff
Fetching https://golang.org/x/image/tiff?go-get=1
Parsing meta tags from https://golang.org/x/image/tiff?go-get=1 (status code 200)
get "golang.org/x/image/tiff": found meta tag get.metaImport{Prefix:"golang.org/x/image", VCS:"git", RepoRoot:"https://go.googlesource.com/image"} at https://golang.org/x/image/tiff?go-get=1
get "golang.org/x/image/tiff": verifying non-authoritative meta tag
Fetching https://golang.org/x/image?go-get=1
Parsing meta tags from https://golang.org/x/image?go-get=1 (status code 200)
golang.org/x/image (download)
# cd .; git clone https://go.googlesource.com/image /Users/yejianfeng/Documents/gopath/src/golang.org/x/image
Cloning into '/Users/yejianfeng/Documents/gopath/src/golang.org/x/image'...
fatal: unable to access 'https://go.googlesource.com/image/': Failed to connect to go.googlesource.com port 443: Operation timed out
package golang.org/x/image/tiff: exit status 128
設置git的http_proxy
大致再搜了一下,是git的http_proxy沒有設置好。
於是做了一下設置:
git config --global http.proxy http://127.0.0.1:61745
終於可以了
go get -v golang.org/x/image/tiff
Fetching https://golang.org/x/image/tiff?go-get=1
Parsing meta tags from https://golang.org/x/image/tiff?go-get=1 (status code 200)
get "golang.org/x/image/tiff": found meta tag get.metaImport{Prefix:"golang.org/x/image", VCS:"git", RepoRoot:"https://go.googlesource.com/image"} at https://golang.org/x/image/tiff?go-get=1
get "golang.org/x/image/tiff": verifying non-authoritative meta tag
Fetching https://golang.org/x/image?go-get=1
Parsing meta tags from https://golang.org/x/image?go-get=1 (status code 200)
golang.org/x/image (download)
golang.org/x/image/tiff/lzw
golang.org/x/image/tiff
也可以很方便使用 go get -u 來下載項目的依賴了。
取消
session的http_proxy是關閉session之后會取消的。
但是git的http.proxy這里是設置的全局的,我們下載完成之后,希望進行取消的話,執行操作:
git config --global --unset http.proxy
后記
據說現在有