go mod 私有仓库管理

作者: 太白菜Rennbon | 来源:发表于2019-08-14 09:52 被阅读20次

    go mod管理下添加私有库

    • go get -v mygitlab.com/name/repository
    • go.mod 会将mygitlab.com/name/repository库添加到require中

    配置go get到私有仓库

    以下为将ssh rewrite为https

    git config --global url."https://mygitlab.com/".insteadOf "ssh://git@mygitlab.com:"
    

    配置完后

    # 查看配置
    cat ~/.gitconfig
    
    [url "https://mygitlab.com/"]
            insteadOf = ssh://git@mygitlab.com:
    

    也可以直接vim 编辑配置

    require私有仓库

    如果GOPROXY如果有代理的话需要先清空,等该类私有仓库OK后再设置代理

    export GOPROXY=
    go get -v -insecure mygitlab.com/name/repository
    GOPROXY=https://goproxy.io
    

    之后的go mod指令管理

    在多人维护的时候,或者持续集成的时候需要2种都tidy一下

    export GOPROXY=
    go mod tidy
    export GOPROXY=https://goproxy.io
    go mod tidy
    
    

    如果不成功可能是rewrite配置问题

    检测指令,在go get不成功的时候会提示失败原因,
    其中可能会有如下指令,可以将其记录后,重新配置
    git url rewrite 直到以下指令成功运行

    git ls-remote -q ssh://git@mygitlab.com/name/repository.git
    
    #成功显示
    abcdefgabcdefgabcdefgabcdefgabcdefgabcde    HEAD
    abcdefgabcdefgabcdefgabcdefgabcdefgabcde    refs/heads/master
    

    感谢同事木易提供的资料

    相关文章

      网友评论

        本文标题:go mod 私有仓库管理

        本文链接:https://www.haomeiwen.com/subject/duvwjctx.html