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

basic generator for the boilerplate of an endpoint definition #70 #77

Closed
wants to merge 2 commits into from

Conversation

dahernan
Copy link

This is a starting point to generate boilerplate code for a given endpoint (I don't expect this PR to be merged, could be use it as inspiration, or maybe try another approach to solve the problem).

Steps to generate boilerplate:

//go:generate go run ../gen-cmd/main.go packageName
//go:generate go fmt
  • Generate the boilerplate doing:
$ cd process
$ go generate
  • The generated file will be process_definition.go

Know issues

  • Uses relatives paths to refer the template and the generator command
  • I don't like the way I get the packageName as an argument in the generation, to use it as a filename

}

func buildAst(pck string) *ast.File {
definitions := pck + ".go"
Copy link
Author

Choose a reason for hiding this comment

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

Not nice to get the file from the packageName requires the convention of the file packageName.go

@ernesto-jimenez
Copy link

@dahernan FYI, rather than running go fmt you can use stdlib's go/format package to format your generated code before writing it to a file.

@peterbourgon
Copy link
Member

Thank you very much for the initial code and thoughts! I will doubtless refer to this in any future work. I am tidying up the issues and PRs and will close this for now.

@dahernan
Copy link
Author

My pleasure, thank you 😄

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.

3 participants