Search code examples
gogoproxy

Manually Download and Place a golang mod file


I am in China and I am compiling a program on linux. The problem is that golang related things are blocked in China. I have tried many proxies but I can't find a solutuion. Can some one please explain me where to manually put this file. I can open it in browser but i don' know where to place it.

go: github.com/onsi/[email protected]: Get "https://proxy.golang.org/github.com/onsi/gomega/@v/v1.17.0.mod": dial tcp 172.217.163.49:443: i/o timeout go: downloading github.com/pkg/errors v0.9.1


Solution

  • As an example to use a proxy, you can refer to this repo which is used for china Gophers and you can check the documentation on this site. you may use another proxy link but the method is the same.

    • macOS or Linux

    Open your terminal and execute

    $ export GO111MODULE=on
    $ export GOPROXY=https://goproxy.cn
    

    or

    $ echo "export GO111MODULE=on" >> ~/.profile
    $ echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
    $ source ~/.profile
    

    done.

    • Windows

    Open your PowerShell and execute

    C:\> $env:GO111MODULE = "on"
    C:\> $env:GOPROXY = "https://goproxy.cn"
    

    if you want to make exceptions you can try:-

    # Set the GOPROXY environment variable
    export GOPROXY=https://goproxy.io,direct
    # Set environment variable allow bypassing the proxy for specified repos (optional)
    export GOPRIVATE=git.mycompany.com,github.com/my/private