• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..17-Feb-2020-

templates/H17-Feb-2020-6149

testdata/H17-Feb-2020-1,2331,063

.ignoreH A D17-Feb-202014 21

README.mdH A D17-Feb-20201.7 KiB5547

arg.goH A D17-Feb-2020624 3730

ast_helpers.goH A D17-Feb-20204.1 KiB210182

ast_templates.goH A D17-Feb-20201.8 KiB125

deflayout.goH A D17-Feb-20201.5 KiB6448

flatlayout.goH A D17-Feb-2020742 4029

interface.goH A D17-Feb-20201.9 KiB7155

main.goH A D17-Feb-20203.3 KiB157122

main_test.goH A D17-Feb-20202.6 KiB11897

method.goH A D17-Feb-20205.3 KiB221184

parsevisitor.goH A D17-Feb-20203.3 KiB179154

path_test.goH A D17-Feb-20201.6 KiB5550

replacewalk.goH A D17-Feb-202015.1 KiB760649

sourcecontext.goH A D17-Feb-20201 KiB5446

transform.goH A D17-Feb-20205 KiB231194

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