-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add kitgen README #743
Merged
Merged
Add kitgen README #743
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# kitgen | ||
kitgen is an experimental code generation utility that helps with some of the | ||
boilerplate code required to implement the "onion" pattern `go-kit` utilizes. | ||
|
||
## Usage | ||
Before using this tool please explore the [testdata]() directory for examples | ||
of the inputs it requires and the outputs that will be produced. _You may not | ||
need this tool._ If you are new to and just learning `go-kit` or if your use | ||
case involves introducing `go-kit` to an existing codebase you are better | ||
suited by slowly building out the "onion" by hand. | ||
|
||
Before starting you need to *install* `kitgen` utility — see instructions below. | ||
1. **Define** your service. Create a `.go` file with the definition of your | ||
Service interface and any of the custom types it refers to: | ||
```go | ||
// service.go | ||
package profilesvc // don't forget to name your package | ||
|
||
type Service interface { | ||
PostProfile(ctx context.Context, p Profile) error | ||
// ... | ||
} | ||
type Profile struct { | ||
ID string `json:"id"` | ||
Name string `json:"name,omitempty"` | ||
// ... | ||
} | ||
``` | ||
2. **Generate** your code. Run the following command: | ||
```sh | ||
kitgen ./service.go | ||
# kitgen has a couple of flags that you may find useful | ||
|
||
# keep all code in the root directory | ||
kitgen -repo-layout flat ./service.go | ||
|
||
# put generated code elsewhere | ||
kitgen -target-dir ~/Projects/gohome/src/home.com/kitchenservice/brewcoffee | ||
``` | ||
|
||
## Installation | ||
1. **Fetch** the `inlinefiles` utility. Go generate will use it to create your | ||
code: | ||
``` | ||
go get github.com/nyarly/inlinefiles | ||
``` | ||
2. **Install** the binary for easy access to `kitgen`. Run the following commands: | ||
```sh | ||
cd $GOPATH/src/github.com/go-kit/kit/cmd/kitgen | ||
go install | ||
|
||
# Check installation by running: | ||
kitgen -h | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@nyarly I went off your profilesvc example in writing this, and now I realize that kitgen doesn't work on an input containing type definitions (and single interface). Not sure what's up.
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.
@nyarly — found what broke the codegen. See #745