• go get golang.org/x 包失败解决方法


    由于墙的原因,国内使用 go get安装golang 官方包可能会失败

    解决方法

    方法1 [不需要翻墙]

    Win10下相关配置:
    GOPATH : E:go

    安装记录:

    E:>go get -u -v golang.org/x/crypto/...
    Fetching https://golang.org/x/crypto?go-get=1
    https fetch failed: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
    package golang.org/x/crypto/...: unrecognized import path "golang.org/x/crypto/..." (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
    
    E:>mkdir %GOPATH%srcgolang.orgx
    E:>cd %GOPATH%srcgolang.orgx
    E:gosrcgolang.orgx>git clone https://github.com/golang/crypto.git
    
    E:gosrcgolang.orgx>go install golang.org/x/crypto
    can't load package: package golang.org/x/crypto: no Go files in E:gosrcgolang.orgxcrypto
    
    E:gosrcgolang.orgx>go install golang.org/x/crypto/...
    cryptolake2blake2bAVX2_amd64.go:9:8: cannot find package "golang.org/x/sys/cpu" in any of:
            C:Gosrcgolang.orgxsyscpu (from $GOROOT)
            E:gosrcgolang.orgxsyscpu (from $GOPATH)
    cryptossh	erminalutil_windows.go:22:2: cannot find package "golang.org/x/sys/windows" in any of:
            C:Gosrcgolang.orgxsyswindows (from $GOROOT)
            E:gosrcgolang.orgxsyswindows (from $GOPATH)
            
    E:gosrcgolang.orgx>go get -u -v golang.org/x/sys
    Fetching https://golang.org/x/sys?go-get=1
    https fetch failed: Get  
    
    E:gosrcgolang.orgx>git clone https://github.com/golang/sys.git
    E:gosrcgolang.orgx>go install golang.org/x/sys/...
    E:gosrcgolang.orgx>go install golang.org/x/crypto/...
    E:gosrcgolang.orgx>ls E:gopkgwindows_amd64golang.orgx
    crypto  sys
    

    1) 需要翻墙,设置http代理

    windows下:

    set http_proxy=代理ip:port (临时有效)
    set HTTPS_PROXY=代理ip:port (临时有效)
    set ALL_PROXY=代理ip:port(临时有效)
    

    linux下:

    export http_proxy=代理ip:port (临时有效)
    export HTTPS_PROXY=代理ip:port (临时有效)
    或者合成一条
    export ALL_PROXY=代理ip:port (临时有效)
    

    这里使用的是shadowsock5配合cow
    cow github地址
    cow release地址

    E:go>ls
    cow-win64-0.9.8
    E:go>cd cow-win64-0.9.8
    E:gocow-win64-0.9.8>mv rc.txt rc.txt_bak
    # 手动修改rc.txt,修改后内容如下
    E:gocow-win64-0.9.8>cat rc.txt
    listen = http://127.0.0.1:7777
    proxy = socks5://127.0.0.1:1080
    E:gocow-win64-0.9.8>cow.exe rc.txt -request -reply -v
    2017/06/29 22:58:00 COW 0.9.8 listen http 127.0.0.1:7777, PAC url http://127.0.0.1:7777/pac
    
    #打开命令一个cmd终端(curl需要自行安装,并添加入环境变量PATH中)
    E:>curl https://www.google.com
    curl: (7) Failed to connect to www.google.com port 443: Timed out
    # 方式1: 直接通过`-x`指定代理
    E:> curl -x http://127.0.0.1:7777 www.google.com
    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" ht
    ....
    # 方式2: 设置http/https代理,注意http_proxy是小写,HTTPS_PROXY是大写
    E:>set http_proxy=http://127.0.0.1:7777
    E:>set HTTPS_PROXY=http://127.0.0.1:7777
    E:> curl www.google.com
    <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" ht
    ....
    
    # 此时原终端显示
    E:gocow-win64-0.9.8>cow.exe -request -v
    2017/06/29 23:17:59 COW 0.9.8 listen http 127.0.0.1:7777, PAC url http://127.0.0.1:7777/pac
    [>>>>>] 2017/06/29 23:18:08 cli(127.0.0.1:5502) request  CONNECT www.google.com:443
    CONNECT www.google.com:443 HTTP/1.1
    Host: www.google.com:443
    User-Agent: curl/7.55.1
    Connection: keep-alive
    
    [>>>>>] 2017/06/29 23:18:31 cli(127.0.0.1:5544) request  CONNECT www.google.com:443
    CONNECT www.google.com:443 HTTP/1.1
    Host: www.google.com:443
    User-Agent: curl/7.55.1
    Connection: keep-alive
    # 说明cow http代理成功
    
    
    # cow启动正常后,即可成功安装crypto 
    E:>go get -u -v golang.org/x/crypto/...
    Fetching https://golang.org/x/crypto?go-get=1
    Parsing meta tags from https://golang.org/x/crypto?go-get=1 (status code 200)
    get "golang.org/x/crypto": found meta tag get.metaImport{Prefix:"golang.org/x/crypto", VCS:"git", RepoRoot:"https://go.googlesource.com/crypto"} at https://golang.org/x/crypto?go-get=1
    golang.org/x/crypto (download)
    ...
    get "golang.org/x/sys/windows": verifying non-authoritative meta tag
    golang.org/x/sys/windows
    golang.org/x/crypto/ssh/terminal
    # 成功安装
    
  • 相关阅读:
    文档生成器
    jenkins多分支版本备份
    jenkins发布控制版本号和同步
    py导出时段报表
    jenkins多分支回滚总结文
    jenkins单分支版本备份
    k8s多pod查询日志脚本
    php 0425
    php 0418
    php 0422
  • 原文地址:https://www.cnblogs.com/hupeng1234/p/9727170.html
Copyright © 2020-2023  润新知