-
Notifications
You must be signed in to change notification settings - Fork 111
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
Generate less boilerplate code when making a new Go module #4668
Generate less boilerplate code when making a new Go module #4668
Conversation
<-ctx.Done() | ||
return nil | ||
// ModularMain can take multiple APIModel arguments, if your module implements multiple models. | ||
module.ModularMain(resource.APIModel{ {{.ResourceSubtype}}.API, models.{{.ModelPascal}}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I don't put a space between the {
and the {{
, it fails with Error: Unable to generate module: template: tmpl-main.go:12: unexpected "{" in command
. I'd prefer to remove the space, but don't know how to get that to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, \{{{
gives the same error, and {\{{
puts a literal backslash in the generated main.go
, resulting in compiler errors later. Perhaps having the space is the least bad option. 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the space doesn't bother me too much! i agree i think its the best option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! one question - you said "nearly all modules can have a 1-line main function", so how does this change affect the modules that need more than this?
TBH, I said "nearly" because I was afraid of saying "all." 🙃 Show me a module where this doesn't work, and I'm confident its creator knows to do something different. edit: |
2f4ef4f
to
81d257a
Compare
Rebased to fix conflicts with #4670... |
This is a follow-up to #4455.
Nearly all modules can really have a 1-line
main
function, rather than all the boilerplate that gets generated in the current version.Tried locally: running
./main module generate
can make a new codebase whosemain.go
looks like this:Running
make
not only successfully compiles everything, butmain.go
gets cleaned up like this (note the reordering of the imports, and the space removed from theAPIModel
constructor):