Skip to content

Fix v2.0.0 main.go importing v1 library path (option 1 from #90)#91

Open
veggiemonk wants to merge 2 commits into
campoy:v2from
veggiemonk:fix/v2-self-import
Open

Fix v2.0.0 main.go importing v1 library path (option 1 from #90)#91
veggiemonk wants to merge 2 commits into
campoy:v2from
veggiemonk:fix/v2-self-import

Conversation

@veggiemonk
Copy link
Copy Markdown

@veggiemonk veggiemonk commented May 16, 2026

Implements option 1 from #90: fix main.go and retag.

Problem

On the v2 branch, go.mod declares the module as github.com/campoy/embedmd/v2, but main.go imports the v1 library path:

import (
    ...
    "github.com/campoy/embedmd/embedmd"   // ← v1 path
    ...
)

So the v2.0.0 binary actually executes v1 library code, and any consumer adding embedmd v2 as a Go tool pulls in both module versions transitively. Full repro and analysis in #90.

Changes

  1. main.go — change the import to github.com/campoy/embedmd/v2/embedmd. The three embedmd.Process(...) call sites now pass context.Background() to match the v2 Process signature (the context parameter added in commit f18280f, which is what bumped the module to v2 in the first place).

  2. embedmd/embedmd_test.go — same context fix. The in-package test never had its Process call updated when the signature changed, so go test ./... couldn't even compile on this branch. Splitting it into a separate commit keeps the cmd vs library fixes independent.

Verification

go build ./...     # passes
go vet ./...       # passes
go test ./...      # see note below

Known pre-existing issue (not addressed here)

TestProcess/embedding_code_from_a_bad_URL still fails after this PR:

expected: "... parse https://fakeurl.com main.go: invalid character ..."
got:      "... parse \"https://fakeurl.com main.go\": invalid character ..."

This is a net/url error-format change in newer Go versions (URLs are now quoted in parse errors). Independent of #90 and predates this PR — happy to send a separate fix if you'd like.

Suggested follow-up

After merge, tag v2.0.1. Existing v2.0.0 consumers update once and the dual-version dependency disappears.

main.go imported "github.com/campoy/embedmd/embedmd" (v1 path) while go.mod declared the module as github.com/campoy/embedmd/v2. As a result, the v2.0.0 binary executes the v1 library code, and any consumer that adds embedmd v2 as a Go tool pulls in both module versions transitively.

Switch the import to "github.com/campoy/embedmd/v2/embedmd" so the v2 binary uses its own library copy. main.go's three Process call sites are updated to pass context.Background() to match the v2 Process signature added in this branch.

Fixes campoy#90.
The v2 branch added a context.Context parameter to Process but the in-package test never updated its call site, so the embedmd test package failed to compile. Add context.Background() to match the v2 Process signature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant