返回提示词目录第 1415 页

Go模块主版本迁移与发布准备

调整模块路径和内部引用,验证构建与测试,并生成版本标签命令及使用方迁移指南。

完整提示词

<context>
Go treats a new major version as a different module. From v2 on, the module path in go.mod must end in the major suffix (`/v2`), every import inside the module must use that path, and the tag must be `v2.0.0` on a commit whose go.mod declares it. The common mistakes: tagging `v2.0.0` without changing the module path, so the go command reports the version as `+incompatible` or refuses it; forgetting to update internal imports, so v2 code silently imports v1 packages; or changing the path in a way the proxy has already cached. There are two layouts. Major branch: change go.mod on a branch or on main and keep tags on it, which is simpler and most common now. Major subdirectory: copy the code into a `v2/` folder, which keeps v1 and v2 buildable from one branch and works with older tooling, at the cost of duplication. Tags are immutable in the module proxy and checksum database, so a bad tag cannot be fixed by retagging; it must be retracted and replaced with a new version. Modules in subdirectories of a repository use prefixed tags (`sub/v2.0.0`).

{{> guardrails/investigate-before-answering}}

Module:
<module>
{{module}}
</module>
</context>

<task>
1. Read go.mod, the existing tags, directory layout (single module or several), CI config and any tools that embed the module path (code generators, docs, examples).
2. Recommend the major-branch or major-subdirectory layout for this repository with the reason.
3. Make the changes: update the module path in go.mod with the `/vN` suffix, rewrite every import of the module's own packages to the new path, update generated code, examples, docs and badges, and keep the breaking changes themselves in focused commits.
4. Run `go build ./...`, `go vet ./...` and the tests, then check that no file still imports the old path.
5. Tagging: give the exact tag name (with the subdirectory prefix if needed), say to tag a pre-release such as `vN.0.0-rc.1` first and test it from a clean consumer project, and how to fix a mistake with a `retract` directive and a new version rather than moving a tag.
6. Importer guide: the `go get` command, the import path change, how to migrate imports across a codebase, and the main breaking changes.
7. Old major: how v1 fixes are released from a branch, and whether to add a deprecation comment to the v1 go.mod.
</task>

<constraints>
- Do not push tags or branches, and do not delete or move existing tags; give the commands and let the user run them.
- Do not mix unrelated refactors into the module path change.
- If the repository holds several modules, change only the one named and say which others import it.
- Do not claim a version is published or fetchable from the proxy; you can only verify local builds.
{{> guardrails/verify-before-done}}
</constraints>

<output_format>
Use the contract's section headings in order. Changes made as a list of files with one line each. Tagging as exact commands in a fenced block. Importer guide in a fenced markdown block ready for the release notes. Verified lists commands run and results.
</output_format>

可替换内容

  • {{> guardrails/investigate-before-answering}}
  • {{module}}
  • {{> guardrails/verify-before-done}}

分类与标签

编程开发、模块版本管理、导入路径迁移、开源发布、发布说明、构建验证

前往 AI 图片创作