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

Support generating structs only, without package decleration. #18

Closed
meblum opened this issue Jul 29, 2024 · 9 comments · Fixed by #19
Closed

Support generating structs only, without package decleration. #18

meblum opened this issue Jul 29, 2024 · 9 comments · Fixed by #19
Assignees

Comments

@meblum
Copy link
Contributor

meblum commented Jul 29, 2024

An empty string as package name should be treated as a "no-package" remove the package ... line.

@twpayne
Copy link
Owner

twpayne commented Jul 29, 2024

If there is no package line then the output is not a valid Go source file. See https://go.dev/ref/spec#Source_file_organization.

@meblum
Copy link
Contributor Author

meblum commented Jul 29, 2024

Right, I'd like to append the output to an existing go file.

@twpayne
Copy link
Owner

twpayne commented Jul 29, 2024

OK, but why append? What is the specific case where multiple source files does not work?

@meblum
Copy link
Contributor Author

meblum commented Jul 29, 2024

Say I have an existing go file and I just need to add a few types. Currently I'd need to manually strip the package declaration.

Happy to submit a PR

@twpayne
Copy link
Owner

twpayne commented Jul 29, 2024

Say I have an existing go file and I just need to add a few types. Currently I'd need to manually strip the package declaration.

In this case the few types can be added in a separate Go source file in the same package.

What is your specific workflow that requires appending? Note that:

  • Appending breaks idempotency, as you always append type definitions rather than replacing previous type definitions, which leads to invalid files as the same type will be defined multiple times.

  • Appending is not compatible with //go:generate. go-xmlstruct is designed to work with //go:generate.

@meblum
Copy link
Contributor Author

meblum commented Jul 29, 2024

In this case the few types can be added in a separate Go source file in the same package.

I don't like separating the types from the function that use them.

What is your specific workflow that requires appending?

I have an existing package where I want to add some type. It's a one-time addition, not based on a ci/cd workflow.

Appending is not compatible with //go:generate.

Omitting the package line where en empty string is supplied as the package name is not a breaking change, as currently it will output just "package" which is not valid either.

@twpayne
Copy link
Owner

twpayne commented Jul 29, 2024

Omitting the package line where en empty string is supplied as the package name is not a breaking change, as currently it will output just "package" which is not valid either.

Good point. OK happy to accept a PR for this :)

@twpayne
Copy link
Owner

twpayne commented Jul 31, 2024

Thanks for the PRs. I've pushed a new version with tag v1.2.0 which includes these and a fix for #21.

@meblum
Copy link
Contributor Author

meblum commented Jul 31, 2024

Thanks to you! Appreciate it.

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 a pull request may close this issue.

2 participants