go - Github 操作 : golang cannot find package

标签 go github-actions

我将示例 github 操作设置到我的存储库。片段在这里。

jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:

    - name: Set up Go 1.x
      uses: actions/setup-go@v2
      with:
        go-version: ^1.13
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2

    - name: Get dependencies
      run: |
        go get -v -t -d ./...
        if [ -f Gopkg.toml ]; then
            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
            dep ensure
        fi

但是作业在 Get dependencies 处失败。错误在这里。

package github.com/<organization-account>/<repo-name>/api/domain/repo: cannot find package "github.com/<organization-account>/<repo-name>/api/domain/repo" in any of:
    /opt/hostedtoolcache/go/1.14.4/x64/src/github.com/<organization-account>/<repo-name>/api/domain/repo (from $GOROOT)
    /home/runner/go/src/github.com/<organization-account>/<repo-name>/api/domain/repo (from $GOPATH)

当然。当 go run main.go 时,我的代码在本地运行。我有 go.modgo.sum

最佳答案

This is not a correct answer for the OP, but may help someone reaching here from searching.

在您的 go 项目的根目录中:

go mod init
go mod tidy

提交并推送到 github,它现在应该可以工作了。

关于go - Github 操作 : golang cannot find package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62945517/

相关文章:

npm - Verdaccio:如何使用正确的凭据从 Github Actions 发布到自定义服务器?

尽管所有需求均已成功,但 GitHub Actions 作业被跳过

go - 检查 channel 的值

json - 在 Go 中表示 JSON 策略

go - 在响应中包含 err.Error() 总是安全的吗?

github-actions - GitHub Actions 检查空调度输入

continuous-integration - 如何在 Github Actions 上使用 Yarn 3.5 版? ("Error: cannot find module .../yarn-3.5.0.cjs")

sql - 包含 % 字符的数据库查询的扫描结果

go - 如何在模板内的urlfor函数中选择模块名称

通过 Github Actions CI/CD 访问服务器时 Git Permission denied (publickey)