README.md
1# kitgen
2kitgen is an experimental code generation utility that helps with some of the
3boilerplate code required to implement the "onion" pattern `go-kit` utilizes.
4
5## Usage
6Before using this tool please explore the [testdata]() directory for examples
7of the inputs it requires and the outputs that will be produced. _You may not
8need this tool._ If you are new to and just learning `go-kit` or if your use
9case involves introducing `go-kit` to an existing codebase you are better
10suited by slowly building out the "onion" by hand.
11
12Before starting you need to *install* `kitgen` utility — see instructions below.
131. **Define** your service. Create a `.go` file with the definition of your
14Service interface and any of the custom types it refers to:
15```go
16// service.go
17package profilesvc // don't forget to name your package
18
19type Service interface {
20 PostProfile(ctx context.Context, p Profile) error
21 // ...
22}
23type Profile struct {
24 ID string `json:"id"`
25 Name string `json:"name,omitempty"`
26 // ...
27}
28```
292. **Generate** your code. Run the following command:
30```sh
31kitgen ./service.go
32# kitgen has a couple of flags that you may find useful
33
34# keep all code in the root directory
35kitgen -repo-layout flat ./service.go
36
37# put generated code elsewhere
38kitgen -target-dir ~/Projects/gohome/src/home.com/kitchenservice/brewcoffee
39```
40
41## Installation
421. **Fetch** the `inlinefiles` utility. Go generate will use it to create your
43code:
44```
45go get github.com/nyarly/inlinefiles
46```
472. **Install** the binary for easy access to `kitgen`. Run the following commands:
48```sh
49cd $GOPATH/src/github.com/go-kit/kit/cmd/kitgen
50go install
51
52# Check installation by running:
53kitgen -h
54```
55