How to set GOPRIVATE environment variable

后端 未结 2 1572
不思量自难忘°
不思量自难忘° 2020-12-12 17:21

I started working on a Go project and it uses some private modules from Github private repos and whenever I try to run go run main.go it gives me a

2条回答
  •  抹茶落季
    2020-12-12 18:02

    Short Answer:

    go env -w GOPRIVATE=github.com/repoURL/private-repo
    

    OR

    If you want to allow all private repos from your organization

    go env -w GOPRIVATE=github.com//*
    

    Long Answer:

    Check "Module configuration for non-public modules" for more information:

    The GOPRIVATE environment variable controls which modules the go command considers to be private (not available publicly) and should therefore not use the proxy or checksum database. The variable is a comma-separated list of glob patterns (in the syntax of Go's path.Match) of module path prefixes. For example,

     GOPRIVATE=*.corp.example.com,rsc.io/private
    

    causes the go command to treat as private any module with a path prefix matching either pattern, including git.corp.example.com/xyzzy, rsc.io/private, and rsc.io/private/quux.

    . .

    The 'go env -w' command (see 'go help env') can be used to set these variables for future go command invocations.


    Note on the usage of ssh:

    If you use ssh to access git repo (locally hosted), you might want to add the following to your ~/.gitconfig:

    [url "ssh://git@git.local.intranet/"]
           insteadOf = https://git.local.intranet/
    

    for the go commands to be able to access the git server.

提交回复
热议问题