Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entproto: add option to specify Go package name #616

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iarunsaragadam
Copy link

This PR adds a WithGoPkg extension option that allows customizing the Go package name used in the generated generate.go files.

What does this PR do?

  • Adds a goPkg field to the Extension struct
  • Implements a WithGoPkg option function to set this field
  • Modifies the protocGenerateGo method to use the specified package name or fall back to the derived name
  • Adds tests to verify the new behavior

Why is this needed?

By default, the package name is derived from the last part of the proto package, but this option enables explicit control when needed. This is useful for cases where:

  • The derived package name conflicts with Go naming conventions
  • Users want to align package names across generated code
  • The proto package structure doesn't map well to the desired Go package structure

Test Plan

Added unit tests that verify:

  • The WithGoPkg option correctly sets the extension's package name
  • The package extraction logic works correctly with various inputs
  • Default behavior is preserved when no custom package is specified

Adds WithGoPkg extension option that allows customizing the Go package
name used in the generated generate.go files. By default, the package
name is still derived from the last part of the proto package, but
this option enables explicit control when needed.

This is useful for cases where the derived package name conflicts with
Go naming conventions or when users want to align package names across
generated code.
Introduces extension_test.go with test cases that verify the
WithGoPkg option correctly sets custom Go package names in
generated files.

Tests cover both the default behavior (deriving package name
from proto package) and the custom package name scenario,
ensuring backward compatibility while adding the new feature.
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.

None yet

1 participant