Go Microservice Skeleton

A template/skeleton project for creating new Go microservices. This project demonstrates patterns and integration of common technologies, serving as a copy-paste starting point for new services rather than a complete production implementation.
Table of Contents
Requirements
- Go 1.27+ (tested with Go 1.27.1 or later)
- Docker (for containerized builds)
- Make (for development commands)
- Kafka (optional, for message broker features)
Technologies Demonstrated
- Go: Modern Go service with proper project structure
- Docker: Containerization with multi-stage builds
- Kubernetes: Complete deployment manifests (Deployment/StatefulSet options)
- Kafka: Message broker integration with producers/consumers
- BoltDB: Local embedded database for persistent storage
- HTTP Services: RESTful API with standard endpoints
- Monitoring: Prometheus metrics and Sentry error tracking
- Security: Comprehensive vulnerability scanning and license management
Installation
As a template project, you typically copy this repository rather than installing it as a dependency. However, if you need to reference it:
go get github.com/bborbe/go-skeleton
Quick Start
# Install dependencies
make deps
# Run the service locally
make run
# Run full development workflow
make precommit
Standard Endpoints
| Endpoint |
Description |
/healthz |
Health check |
/readiness |
Readiness check |
/metrics |
Prometheus metrics |
/resetdb |
Database reset |
/resetbucket/{BucketName} |
Reset a single database bucket |
/setloglevel/{level} |
Dynamic log level adjustment |
/gc |
Run garbage collection |
/testloglevel |
Test logging at all levels |
/sentryalert |
Test Sentry integration |
Development Commands
make ensure # Dependency management (go mod tidy, verify)
make format # Code formatting (gofmt, goimports-reviser, golines)
make generate # Code generation
make test # Run tests with coverage
make check # Security and quality checks (lint, vet, vulncheck, osv-scanner, trivy)
make precommit # Complete development workflow
Configuration
Configuration is managed through environment variables. See example.env for development defaults.
Runtime Configuration
| Variable |
Description |
Default |
KAFKA_BROKERS |
Kafka broker addresses |
(required) |
LISTEN |
HTTP server listen address |
(required) |
SENTRY_DSN |
Sentry error tracking DSN |
(required for production) |
SENTRY_PROXY |
Sentry proxy URL |
(optional) |
DATADIR |
Database storage directory |
(required) |
BATCH_SIZE |
Kafka batch consume size |
1 |
Build/Deployment Configuration
| Variable |
Description |
DOCKER_REGISTRY |
Docker registry for image publishing |
IMAGE |
Docker image name |
CLUSTER_CONTEXT |
Kubernetes cluster context |
BUILD_GIT_VERSION |
Build version (auto-set in CI/Docker) |
BUILD_GIT_COMMIT |
Build commit hash (auto-set in CI/Docker) |
BUILD_DATE |
Build timestamp (auto-set in CI/Docker) |
Deployment
Kubernetes
The k8s/ directory contains complete Kubernetes manifests:
- Choose between Deployment (
skeleton-deploy.yaml) or StatefulSet (skeleton-sts.yaml)
- Service, Ingress, Secret, and User configurations included
- To activate: Change replicas from 0 → 1
- For Deployment: Delete StatefulSet manifest if using Deployment
Docker
Multi-stage Docker build included. See Dockerfile and Makefile.docker.
make build BUILD_TARGET=sun builds in the sun cluster. A private repository also needs the git-app secret (a GitHub App's APP_ID, INSTALLATION_ID and PEM_KEY) in the build namespace; it is provisioned out of band, and its absence is a supported state — the Job mounts the secret optionally and falls back to an anonymous clone, so a public repository builds with no App credential at all. hack/build-cluster-bootstrap.sh provisions the namespace and both registry pull secrets (buildkit-push, buildkit-push-nuke), so a freshly bootstrapped namespace builds a public repo with no further setup. See docs/build-migration-guide.md § Private repositories.
Releasing
Releases are cut by the github-releaser pipeline from the ## Unreleased section of CHANGELOG.md. The agent rewrites that heading to ## vX.Y.Z, commits, tags, and pushes directly to master — so a non-empty ## Unreleased is the trigger, and merging a CHANGELOG bullet is what starts a release.
This repo is released by the dev-stage pipeline only. It is the dev pipeline's canary, so the prod release watcher excludes it (!github.com/bborbe/go-skeleton) and the dev watcher's allowlist names it alone — the two stages watch disjoint repo sets so their task IDs cannot collide.
master is covered by the master-protection ruleset, which requires a pull request and passing status checks. Three actors bypass it: the repository-admin role, the prod-stage releaser App (ben-s-github-releaser, Integration 3907226) and the dev-stage releaser App (ben-s-github-releaser-dev, Integration 3907205). The dev App is the one that has to be there: without it the dev releaser cuts the tag but the push is rejected (GH013 … Changes must be made through a pull request), and since prod never scans this repo, nothing releases at all.
Architecture
Standard Go microservice architecture:
main.go - Application entry point with dependency injection
pkg/factory/ - Factory functions for handler creation
pkg/handler/ - HTTP handlers for various endpoints
- Uses proven libraries for service framework, HTTP handling, Kafka, database, and monitoring
API Documentation
For complete API documentation of the handlers and packages, visit pkg.go.dev.
Testing
Uses Ginkgo BDD framework with Gomega matchers. Run tests with make test or ginkgo run ./....
Example tests are included to demonstrate testing patterns - copy and adapt these when building your service.
Usage as Template
- Copy this repository as a starting point for your new service
- Update service name throughout (replace "skeleton")
- Modify handlers and add your business logic
- Update configuration in
example.env and K8s manifests
- Implement your specific Kafka consumers/producers and database schema
License
BSD-style license. See LICENSE file for details.