Skip to content

Qualified -src/-dst references; remove -external-pkg#3

Open
hacks1ash wants to merge 13 commits into
mainfrom
feat/qualified-refs
Open

Qualified -src/-dst references; remove -external-pkg#3
hacks1ash wants to merge 13 commits into
mainfrom
feat/qualified-refs

Conversation

@hacks1ash

Copy link
Copy Markdown
Owner

Summary

  • Replace -external-pkg with package-qualified -src / -dst values. Three forms supported:
    • Bare (User) — current package
    • Module-relative (models.User or internal/models/request.RequestStruct) — joined to current go.mod module root
    • Full import path (github.com/org/repo/models.User) — loaded as-is
  • Broaden getter detection: any struct (same package, same module, or external) is probed for Get<Field>() methods. New flags -getters (force) and -no-getters (disable) override the auto default.
  • Unify the matcher: MatchCross is gone; Match(src, dst, MatchOptions{...}) is the single entry point. Bind tags work in both same- and cross-package mode.
  • Unify CLI orchestration: RunSamePackage and RunCrossPackage collapse into a single cli.Run that selects the generator based on whether the resolved packages match.
  • Migrate _examples/02-protobuf-integration and README/docs to the new syntax.

Migration

- goxmap -src User -dst ExternalUser -external-pkg github.com/org/repo/proto -bidi
+ goxmap -src User -dst github.com/org/repo/proto.ExternalUser -bidi

Test plan

  • go test ./... passes (6 packages)
  • _examples/01-standard-dto: go generate ./... regenerates byte-identical output to HEAD; go build ./... passes
  • _examples/02-protobuf-integration: cross-package generation against pb.User produces correct imports + bidi mappers; build passes after regen and after cleanup
  • Benchmarks unchanged in order of magnitude (Generated path: 84 ns/op numeric cast, 375 ns/op simple, 542 ns/op nested)

Notes

  • MatchOptions.DstGetters is plumbed but unused (reserved for a future writer-side feature).
  • Pre-1.0; no deprecation alias for -external-pkg. Migration is one-line.

Walk up the directory tree from a given path to locate go.mod,
then extract the module import path using golang.org/x/mod/modfile.

On macOS, t.TempDir() returns /var/... symlink paths while
filepath.EvalSymlinks resolves to /private/var/.... We intentionally
skip EvalSymlinks so the returned moduleDir matches paths constructed
from the same TempDir base, keeping test comparisons consistent.
…egeneration

DiscoverMapperFuncs finds the previously-generated root function in the
package, causing enqueue to treat it as already present and skip it
entirely — producing an output file with only the package header.

Delete the root (and reverse, when bidi) function names from the
discovered set before passing it to GenerateMulti so only genuine
nested-helper mappers are skipped on reuse.
…xample

- Integrated `go:generate` directive to automate mapper generation.
- Replaced manual mapping functions with generated equivalents.
- Updated `.gitignore` to include generated docs and metadata files.
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