Skip to content

Add support for custom package name in generated go file#152

Open
andrzejressel wants to merge 3 commits into
ihciah:masterfrom
andrzejressel:custom_package_name
Open

Add support for custom package name in generated go file#152
andrzejressel wants to merge 3 commits into
ihciah:masterfrom
andrzejressel:custom_package_name

Conversation

@andrzejressel
Copy link
Copy Markdown

@andrzejressel andrzejressel commented Mar 15, 2026

I would like to use generated file from within a library and I cannot have package main there.

@bahlo
Copy link
Copy Markdown

bahlo commented Mar 27, 2026

+1, this would unblock our workflow as well

@lirenjie95 lirenjie95 requested a review from ihciah March 28, 2026 03:55
Copy link
Copy Markdown
Collaborator

@lirenjie95 lirenjie95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for providing this PR! I have a few suggestions:

  1. Could you please add some tests to verify that the changes work correctly? For instance, it would be helpful to test edge cases such as invalid names, Go keywords, or names starting with a number. Additionally, would you mind checking the documentation and updating the support for custom package names if needed? If you want me to help with the validation functions, I’ll be happy to do so!
  2. I noticed that your code ensures the default package name is "main". However, I'm a bit unclear about line 149 — it still returns "main" when the package name is empty. Could you help me understand the reasoning behind this? (I might be missing something here, so please feel free to correct me if I'm mistaken.)

Also cc @ihciah

@andrzejressel
Copy link
Copy Markdown
Author

andrzejressel commented Mar 29, 2026

  1. Then user provide some invalid package it's their problem. I don't think any filtering/checking is needed - Go compiler will return error anyway. I can create additional example example-go-library if needed.
  2. The Default::default() is used everywhere - so the default value is empty string. I guess I can change the type to Option<String> and use main when the option is None.

@quinn
Copy link
Copy Markdown

quinn commented May 21, 2026

i think this change is necessary to make this tool useful (very unlikely main will be used in anything other than an example) any chance this could be merged? thank you!

@lirenjie95
Copy link
Copy Markdown
Collaborator

@ihciah Can you help review this PR? Looks like it’s reasonable and effective.

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.

4 participants