lib-commons
lib-commons
is Lerian’s Go library of shared tools and components, built to help you create resilient, consistent microservices across our ecosystem. It centralizes common logic so you can move faster and focus on what makes your service unique.
With modular, testable, and maintainable building blocks, lib-commons
accelerates development while promoting standardization. From database connectors to observability tools, it gives your services a solid foundation to build on.
Key features
Core components
- Application management – manage your service lifecycle with
app.go
- Context utilities – log, trace, and propagate request metadata with
context.go
- Error handling – standardize business errors and map them to consistent API responses with
errors.go
Database connectors
- PostgreSQL – connection setup, migration support, and helper functions
- MongoDB – simplified configuration and common operations
- Redis – client implementation and reusable helpers
Messaging
- RabbitMQ – ready-to-use client for publishing, consuming, and managing queues and exchanges
Observability
- Logging – a pluggable logging interface with multiple implementations
- Log obfuscation – use the
SECURE_LOG_FIELDS
environment variable to hide sensitive fields from logs - OpenTelemetry – integrated support for tracing, metrics, and logs
- Zap – built-in support for Uber’s Zap structured logging
Utilities
- String helpers – common string manipulation functions
- Type conversion – safely convert between types
- Time helpers – date and time utilities
- OS helpers – tools for interacting with the operating system
- Pointer utilities – simplify working with pointer types
- Transaction processing – validate and handle financial transaction flows
Getting started
Requirements
1. Install the lib
go get github.com/LerianStudio/lib-commons
2. Add the lib to your project
To use lib-commons
, include it in your project’s dependency management. Then, import only the subpackages you need, keeping your dependencies lean and your codebase clean.
Example:
import (
contextutils "github.com/LerianStudio/lib-commons/commons/context"
logutils "github.com/LerianStudio/lib-commons/commons/log"
tx "github.com/LerianStudio/lib-commons/commons/transaction"
)
This gives you direct access to tools like ContextWithLogger
, WithFields
, or ValidateTransactionRequest
, without bringing in unnecessary code.
Commons module
The commons
module is the heart of the library. It provides streamlined, reusable utilities for building robust Go services at Lerian.
It includes:
- Context management – enrich request flows with logging, tracing, and metadata propagation
- Error handling – ensure consistent validation and error responses across services
- Database connectors – manage connections and queries for PostgreSQL, MongoDB, and Redis
- Messaging – interact with RabbitMQ using ergonomic helpers
- Observability – built-in integrations for logging (Zap), metrics, and tracing (OpenTelemetry)
- Utilities – tools for working with strings, types, time, OS, pointers, transactions, shell commands, and networking
Note
For the full list of available tools and functions, check out the Go reference documentation.
Contributing
Contributions are welcome! If you’ve written logic that could benefit other services, let’s bring it into lib-commons.
Just make sure your code is idiomatic and covered by tests.
License
- Apache 2.0 - refer to the LICENSE page for details.
Updated 2 days ago