本文实现通过 github 的 workflow 来迁移到 gcr 上的镜像到 dockerhub 的过程记录。
创建仓库
创建一个 go 的项目
Certainly! The error message you’re encountering, “go: go.mod file not found in current directory or any parent directory; see ‘go help modules’”, indicates that Go is unable to locate a go.mod
file in the current directory or any of its parent directories. This file is essential for managing Go modules and dependencies.
Here are a few steps you can take to resolve this issue:
-
Initialize a Go Module:
- In your project directory, run the following command:
Replace
1
go mod init yourProjectName
yourProjectName
with an appropriate name for your project. This command will create ago.mod
file in the current directory, allowing Go to manage your project’s dependencies¹².
- In your project directory, run the following command:
-
Check Environment Variables:
- Ensure that the environment variable
GO111MODULE
is set correctly. You can set it to one of the following values:auto
: Automatically enable Go modules when ago.mod
file is present.on
: Force Go modules to be enabled.off
: Disable Go modules entirely. To set the variable, run:
1
go env -w GO111MODULE=auto
This will allow Go to automatically enable modules based on the presence of a
go.mod
file²⁴. - Ensure that the environment variable
-
Run
go mod tidy
:- Execute the following command in your project directory:
This command will synchronize your code’s imports with the dependencies listed in the
1
go mod tidy
go.mod
file⁴.
- Execute the following command in your project directory:
Remember that these steps are general guidelines, and you should adapt them to your specific project structure. If you encounter any further issues, feel free to ask for additional assistance! 🚀
源: 与必应的对话, 2024/3/29 (1) go 语言开发时,报“go:go.mod 文件未在当前目录或任何父目录中找到”这个问题怎么解决? - 知乎. https://www.zhihu.com/question/458797990. (2) 如何在 Visual Studio Code 中配置 GO 开发环境 - 知乎 - 知乎专栏. https://zhuanlan.zhihu.com/p/408291483. (3) 请问 vscode 进行 go 调试遇到找不到 mod 文件是什么意思? - 知乎. https://www.zhihu.com/question/514939166. (4) 【Go】エラー「go.mod file not found in current directory or any parent …. https://qiita.com/to3izo/items/f47bbc7b11ef6d2e24cd. (5) Error message “go: go.mod file not found in current directory or any …. https://stackoverflow.com/questions/66894200/error-message-go-go-mod-file-not-found-in-current-directory-or-any-parent-dire.
|
|
接下来测试一下迁移镜像
|
|
接下来把仓库推送到 github 上操作