Go-kit generator is a cli application that generates boilerplate code for your go-kit services.
Because I am lazy, and because it would make it easier for go-kit newcomers to start using it.
go install github.com/kujtimiihoxha/gk
gk
must be run from a project inside the specified $GOPATH
for it to work.
When it is run for the first time it will search for gk.json
configuration file, if it does not find it it will create one
with the default settings.
Inside the project run:
gk new service hello
this will create a new service called HelloService
inside :
project
└───hello
│ └───pkg
│ │ └───service
│ │ │ service.go
service.go
package service
type HelloService interface {
// Write your interface methods
}
Now you need to add the interface methods and initiate your service: e.x:
package service
import "context"
type HelloService interface {
// Write your interface methods
World(ctx context.Context, s string) (rs string, err error)
}
than run :
gk init hello
this will create the service struct
, methods
, endpoints
, transport
.
The final folder structure is the same as addsvc
Every command has the -h
or --help
flag this will give you more info on what the command does and how to use it.
e.x
gk init -h
will return
Initiates a service
Usage:
gk init [flags]
Flags:
-t, --transport string Specify the transport you want to initiate for the service
Global Flags:
-d, --debug If you want to se the debug logs.
--folder string If you want to specify the base folder of the project.
-f, --force Force overide existing files without asking.
--testing If testing the generator.
The example you see here go-kit/kit#70
- Implement support for other transports besides
http
- Implement the update commands, this commands would be used to update an existing service e.x add a new request parameter to a endpoint.
- Implement middleware generator (service,endpoint).
- Implement automatic creation of the service main file.
- Tests tests tests ...
Thanks a lot for contributing.
To test your new features/bug-fixes you need a way to run gk
inside your project this can be done using test_dir
.
Execute this in your command line :
export GK_FOLDER="test_dir"
Create a folder in the gk
repository called test_dir
, now every time you run go run main.go [anything]
gk
will treat test_dir
as the project root.