【问题标题】:How to add go pkg to existing repo?如何将 go pkg 添加到现有仓库?
【发布时间】:2020-09-14 04:32:39
【问题描述】:

我在 github 中有这个 repo,在同一个 repo 中有 cppgo 的库。现在如何在go 中创建go.mod 来导入它?

我在谷歌上搜索过,但都有单独的回购。我该怎么做?

谢谢。

【问题讨论】:

    标签: git go github multi-module go-modules


    【解决方案1】:

    1️⃣。子目录中的初始化模块:

    cd /art/art-go
    
    go mod init github.com/srilakshmikanthanp/art/art-go
    

    2️⃣。为go.mod 文件添加缺失和删除未使用的模块

    cd /art/art-go
    
    go mod tidy
    

    3️⃣.❗️ 因为你有multimodule 项目,你必须将version tag 与子模块声明(<submodul_dir_name>/<version>)添加到符合Semantic Version 规范的子模块中

    git commit -a - m "art/art-go - some changes"
    git tag art-go/v1.0.0
    git push
    git push --tags 
    

    4️⃣。 ☝? 因此,您可以将其导入其他项目中

    module go mod init github.com/srilakshmikanthanp/otherproject
    
    require github.com/srilakshmikanthanp/art/art-go v1.0.0
    
    go 1.15
    

    4️⃣。 ✌? 或get

    go get github.com/srilakshmikanthanp/art/art-go@v1.0.0
    

    输出??

    go: finding github.com/srilakshmikanthanp/art/art-go v1.0.0
    

    【讨论】:

    • 感谢您的回答,正如您所说,我更改了文件夹结构,但是当我导入时会在go plagground 中抛出类似but does not contain package github.com/srilakshmikanthanp/art/art-go/anixt 的错误
    • 你添加版本标签art-go/v1.0.0了吗?
    • ? go get github.com/srilakshmikanthanp/art/art-go@v0.1.0 工作正常?? go: downloading github.com/srilakshmikanthanp/art/art-go v0.1.0
    猜你喜欢
    • 2021-04-07
    • 1970-01-01
    • 2020-04-22
    • 2016-10-09
    • 1970-01-01
    • 2011-10-06
    • 1970-01-01
    • 2022-06-13
    相关资源
    最近更新 更多