Skip to content
/ kk Public

Golang boilerplate code with a CLI tool: easily create, setup and extend Golang projects.

License

Notifications You must be signed in to change notification settings

waler4ik/kk

Repository files navigation

go test gosec Security Check version license

kk - Golang boilerplate CLI tool

Tip

Create, setup and extend a Golang project like a puzzle in seconds

How to use it?

Install

go install github.com/waler4ik/kk@latest

After installation use kk command in your shell.

Init command

Creates a Golang REST server project without endpoints. Chi is used as the default router.

kk init rest github.com/waler4ik/kk-example
kk init -r chi rest github.com/waler4ik/kk-example

Create a Golang REST server project with gin router.

kk init -r gin rest github.com/waler4ik/kk-example

Add command

Creates and wires a REST resource endpoint

kk add resource machines/data

Creates and wires a websocket endpoint. It's based on Melody project. See https://github.com/olahol/melody

kk add ws rest/ws

Creates and wires a prometheus metrics endpoint. See https://prometheus.io/docs/guides/go-application/

kk add metrics /metrics

Adds a secret manager provider based on environment variables.

kk add envsecretmanager

Adds a postgres provider.

kk add postgres

Adds a rabbitmq producer provider.

kk add rabbitmqproducer

OpenAPI / Swagger interface

REST resource endpoints added with kk add come along with swaggo/swag annotations. So you can tell the world how your REST webservice works.

Possible workflow:

  • Generate swagger 2.0 specification with swaggo/swag. Run swag init -g internal/docs/docs.go.
  • Generate a Golang client from previously generated swagger 2.0 specification with go-swagger and use it for your Golang client application or just test your previously generated webservice.

Example project

kk generates projects like this https://github.com/waler4ik/kk-example (chi router, REST endpoints).

Testing locally

After running kk init, build and start your service with the commands below. Then check your endpoints using a tool of your choice.

docker compose build && docker compose up -d

Upcoming features (commands)

  • Add websocket command
  • Generate swagger/openapi specification command
  • Select router within init command (chi, gin, gorilla)
  • Add cucumber godog tests for main workflows, see https://github.com/cucumber/godog
  • Add kubernetes scripts command

Similar approaches

About

Golang boilerplate code with a CLI tool: easily create, setup and extend Golang projects.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published