This project is opinionated Go starter kit / golang boilerplate that uses the golang standards project layout, using best and proven libraries and implements best practices for great foundation of Golang API project.
When I want to start to build Go API project, i don't have a good solid base to start and usually I add the library and add another required thing one by one along the time, and then change again if I find another better library or another better way to do thing. So I tried to research architecture, library and software component/layer that I think better suits to be included for solid golang project.
This project follows SOLID & Clean architecture
- Versioning
- Pagination
- Configuration
- Logging
- Error Handling
- Validation
- Health Check
- Data Seed
- DB Migration
- Run & Manage via CLI Command
- Makefile
- Linter
- Unit Test
- Docker & Docker Compose
- Integration Test sample
Todo:
- Add more examples for service, repository and test
- JWT base Authentication
- Observability/Metrics
- Kubernetes deployment
- Use Cobra for CLI
- Viper for better handling env and config
Github: https://github.com/qreasio/go-starter-kit
Gostarterkit site: https://gostarterkit.com
- Go 1.14
- Base web framework & Routing using github.com/go-chi/chi
- Validation with github.com/go-playground/validator/
- Database with github.com/jmoiron/sqlx
- Logging with go.uber.org/zap
- Migration with github.com/go-migrate/migration
- YAML with gopkg.in/yaml.v2
- Linter with github.com/golangci/golangci-lint
- Go static analysis with staticcheck.io https://github.com/dominikh/go-tools
- Mock generator using github.com/golang/mock
Below are the steps if you want to run locally without docker
-
Set required environment variable
ENV=local
-
Set configuration
Change config/local.yaml configuration value properly and make sure can connect to blank MySQL database properly
-
Run migration
make migrate
-
Add seed data
make seed
-
Run app
make run
-
Open the browser
Visit the url
go test -v ./internal/user/...
Below are the steps if you want to run locally with docker & docker compose
-
Build docker image
Generate the docker imgae by this command:
docker build --rm -t starterkitapi -f dockerfile.api .
-
Run with docker compose
Copy the sample.env to .env and adjust it then run the docker compose with this command:
docker-compose up
-
Open the browser
Visit the url
-
Quit & Cleanup
Click Ctrl+C to quit in console then run these commands below to clean up all things:
docker-compose rm -v
Golang Project Layout https://github.com/golang-standards/project-layout
ArdanLabs Service https://github.com/ardanlabs/service
GORSK - GO(lang) Restful Starter Kit https://github.com/ribice/gorsk/
Go REST API starter kit https://github.com/qiangxue/go-rest-api
Isak Rickyanto
Twitter: @isakric
Personal site: https://rickyanto.com