go-pkgs
A collection of reusable Golang packages for building modern backend services.
π Features
- Lightweight & idiomatic Go packages
- Ready-to-use building blocks for microservices
- Examples included for quick start
- Modular design β use only what you need
π Modules
β
Implemented
grace - Graceful HTTP Server Shutdown
Drop-in replacement for http.ListenAndServe with graceful shutdown handling. Works with any framework (Gin, Echo, standard library, etc.).
go get github.com/davidsugianto/go-pkgs/grace
π Documentation | π‘ Example
httpclient - Simple & Powerful HTTP Client
Lightweight HTTP client wrapper with automatic JSON serialization, context support, and flexible configuration.
go get github.com/davidsugianto/go-pkgs/httpclient
π Documentation | π‘ Example
A lightweight pagination package that helps you handle pagination logic with default values, offset/limit calculation, and total pages.
go get github.com/davidsugianto/go-pkgs/pagination
π Documentation | π‘ Example
config - Configuration Loader
Type-safe configuration loader with JSON and YAML support. Features automatic format detection, generics for type safety, and support for nested structures.
go get github.com/davidsugianto/go-pkgs/config
π Documentation | π‘ Example
response - Consistent API Response Utilities
A lightweight package for creating consistent JSON API responses with a standard format (code, data, error). Provides convenient helper functions for common HTTP status codes. Includes built-in support for Gin framework.
go get github.com/davidsugianto/go-pkgs/response
π Documentation | π‘ Example
redis - Go-Redis Wrapper
A lightweight wrapper around go-redis with helper methods for caching and connection handling. Provides a simple, idiomatic API for Redis operations including strings, hashes, lists, sets, sorted sets, and JSON serialization.
go get github.com/davidsugianto/go-pkgs/redis
π Documentation | π‘ Example
logger - Structured Logging with OpenTelemetry Integration
A structured logging package built on zerolog with automatic OpenTelemetry span context correlation. Provides high-performance, zero-allocation JSON logging with seamless integration for observability platforms like Grafana and Loki.
go get github.com/davidsugianto/go-pkgs/logger
π Documentation | π‘ Example
otel - OpenTelemetry Integration
A comprehensive OpenTelemetry integration package providing unified configuration for distributed tracing, metrics, and logging. Features selective enablement, method chaining API, trace-aware logging, and graceful shutdown.
go get github.com/davidsugianto/go-pkgs/otel
π Documentation | π‘ Example
db - Database Package
Multi-database support with GORM, automated migrations, and OpenTelemetry instrumentation. Supports PostgreSQL, MySQL, and MSSQL with connection pool metrics and embedded schema migrations.
go get github.com/davidsugianto/go-pkgs/db
π Documentation | π‘ Example
π§ Planned
httpserver
Graceful HTTP server with middleware support (logging, recovery, health checks).
config (.env support)
Add .env file support and environment variable overrides to the config package.
workerpool
Goroutine worker pool with configurable concurrency and graceful shutdown.
ratelimiter
In-memory or Redis-based rate limiter using token bucket / leaky bucket.
auth/jwt
JWT authentication helpers for token generation, validation, and middleware.
π Getting Started
1. Prerequisites
- Go 1.25+ installed β Download Go
- (Optional) Docker & Docker Compose for running Redis/DB examples
2. Clone the Repository
git clone https://github.com/davidsugianto/go-pkgs.git
cd go-pkgs
π Roadmap
-
Core Packages
- Implement
grace with graceful HTTP server shutdown
- Implement
httpclient with automatic JSON serialization and context support
- Implement
pagination with offset/limit calculation and total pages
- Implement
config loader with JSON and YAML support
- Implement
response utilities for consistent API responses
- Implement
redis wrapper with connection pool and helper methods
- Implement
logger with OpenTelemetry integration and structured logging
- Implement
otel with unified OpenTelemetry configuration for tracing, metrics, and logging
- Implement
db connector with GORM, migrations, and OpenTelemetry support
- Implement
httpserver with graceful shutdown and middleware support
- Add
.env file support to config package
- Implement
workerpool with job queue and concurrency control
- Implement
ratelimiter with in-memory and Redis support
- Implement
auth/jwt for token generation and validation
-
Examples
- Add usage examples for
grace package
- Add usage examples for
httpclient package
- Add usage examples for
pagination package
- Add usage examples for
config package
- Add usage examples for
response package
- Add usage examples for
redis package
- Add usage examples for
logger package
- Add usage examples for
otel package
- Add usage examples for
db package
- Provide a sample microservice using multiple packages
-
Testing & Quality
- Add unit tests for
grace package
- Add unit tests for
httpclient package
- Add unit tests for
pagination package
- Add unit tests for
config package
- Add unit tests for
response package
- Add unit tests for
redis package
- Add unit tests for
logger package
- Add unit tests for
otel package
- Add unit tests for
db package
- Add integration tests (Redis, DB, HTTP server)
- Add CI pipeline with GitHub Actions (
go test ./..., lint, vet)
- Add Go Report Card and Coverage badge
-
Enhancements
- Add gRPC server wrapper
- Add metrics exporter with Prometheus
- Add distributed tracing middleware with OpenTelemetry
- Add caching abstraction
-
Documentation
- Write README for
grace package
- Write README for
httpclient package
- Write README for
pagination package
- Write README for
config package
- Write README for
response package
- Write README for
redis package
- Write README for
logger package
- Write README for
otel package
- Write README for
db package
- Write package-level docs with
godoc examples
- Add contribution guide (
CONTRIBUTING.md)
- Add code of conduct (
CODE_OF_CONDUCT.md)
π License
MIT License β feel free to use and contribute.