This repository acts as a template for a simple go backend with the focus on not using too much external dependencies.
It utilizes:
- spf13/cobra to create a cli command to run the server
- vektra/mockery to generate mocks from interfaces
- stretchr/testify for simpler testing in general
- 42lm/muxify for a better handling of the default
*http.ServeMux
Copy .envrc.example
cp .envrc.example .envrc
Tip
Use a tool like direnv to load and unload environment variables depending on the current directory.
Install tools (currently only mockery)
go install tool
Setup DB (currently only dynamodb)
docker compose up -d
Run tests
go test ./...
Run server
go run main.go server
Make a request
curl localhost:8080/v1/none
curl localhost:8080/v1/msg/777
curl -X POST localhost:8080/v2/msg/777 -d '{"msg":"test-msg"}'
Generate mocks from interfaces with mockery and use
go generate ./...
go build -ldflags "-X go-backend-skeleton/app/cmd.version=v0.0.0" -o gbs
Make sure you install the go tools:
go install tool
Make sure the protobuf
is installed on your machine. For more info check protobuf.
brew install protobuf