go-utilities

module
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: MIT

README ΒΆ

Go Utilities

A modular collection of reusable Go components to simplify backend development. It includes robust tools for structured logging, resilient HTTP clients, Kafka integration, database utilities, and server setupβ€”engineered for scalability and maintainability.


πŸš€ Features

1. Logger
  • Structured logging with pluggable backends (e.g., zerolog).
  • Context-aware logging with trace IDs and component tagging.
  • Mockable for unit testing.
  • πŸ“˜ Logger Documentation
2. HTTP Client
  • Built-in circuit breaker and retry mechanism via heimdall.
  • Supports GET, POST, PUT, and DELETE requests.
  • Configurable timeouts, retries, and backoff strategies.
  • πŸ“˜ HTTPClient Documentation
3. Kafka
  • Easy setup for Kafka producers and consumers.
  • Compatible with local and AWS MSK environments.
  • Configurable compression, batching, retries, and message encoding.
  • πŸ“˜ Kafka Documentation
4. Database
  • Connection pooling and transaction support.
  • SQL query pagination helpers.
  • Common error handling utilities.
  • πŸ“˜ Database Documentation
5. Server
  • Modular HTTP server setup with customizable middleware.
  • Graceful shutdown support.
  • Built-in middleware for CORS, panic recovery, and request size limits.
  • πŸ“˜ Server Documentation
6. OpenTelemetry
  • Distributed tracing and metrics collection.
  • Support for console, OTLP, and Elastic APM exporters.
  • Automatic HTTP instrumentation via Gin middleware.
  • Context propagation for distributed systems.
  • πŸ“˜ OpenTelemetry Documentation

πŸ“ Project Structure

go-utilities/
β”œβ”€β”€ database/     # DB connection pooling, transactions, pagination
β”œβ”€β”€ httpclient/   # HTTP client with circuit breaker & retries
β”œβ”€β”€ kafka/        # Kafka producer and consumer implementations
β”œβ”€β”€ logger/       # Structured logging utilities
β”œβ”€β”€ otel/         # OpenTelemetry tracing and metrics
β”œβ”€β”€ server/       # HTTP server setup and middleware
β”œβ”€β”€ go.mod        # Module dependencies
β”œβ”€β”€ LICENSE       # License information
└── README.md     # Project documentation

πŸ“¦ Installation

Add the module to your project using:

go get github.com/bignyap/go-utilities

πŸ› οΈ Usage Examples

Logger
import (
    "github.com/bignyap/go-utilities/logger/factory"
    "github.com/bignyap/go-utilities/logger/config"
)

func main() {
    logger := factory.GetGlobalLogger()
    logger.Info("Application started")
}
HTTP Client
import (
    "github.com/bignyap/go-utilities/httpclient"
)

func main() {
    client := httpclient.NewHystixClient("https://api.example.com", httpclient.DefaultConfig(), nil)
    var response map[string]interface{}
    err := client.Get("/endpoint", nil, &response)
    if err != nil {
        panic(err)
    }
}
Kafka Producer
import (
    "github.com/bignyap/go-utilities/kafka"
)

func main() {
    config := &kafka.LocalConfig{
        BrokerSasl: "localhost:9092",
        Topic:      "example-topic",
    }
    producer, _ := kafka.NewLocalProducer(config, nil)
    defer producer.Close()

    producer.SendMessage(map[string]string{"key": "value"})
}
Database
import (
    "log"
    "github.com/bignyap/go-utilities/database"
)

func main() {
    connStr := database.NewConnectionString(
        "localhost", "5432", "user", "password", "dbname", nil,
    )

    db, err := database.NewDatabase(&database.DatabaseConfig{
        Name:             "main-db",            // Optional: useful for logging or multi-DB setups
        Driver:           "postgres",           // Supports: "postgres", "mysql", "sqlite"
        ConnectionString: connStr,
        // ConnectionPoolConfig: nil,           // Optional: uses default pool settings
    })
    if err != nil {
        log.Fatalf("failed to create database: %v", err)
    }

    if err := db.Connection.Connect(); err != nil {
        log.Fatalf("failed to connect: %v", err)
    }
    defer db.Connection.Close()

    log.Println("Database connection established")
}

πŸ“ License

This project is licensed under the MIT License.


🀝 Contributing

We welcome contributions! To contribute:

  1. Fork the repository.
  2. Create a feature or fix branch.
  3. Submit a pull request with a detailed description.

πŸ“¬ Contact

For questions or support, please reach out to the repository owner or open an issue.

Directories ΒΆ

Path Synopsis
Package crypto provides envelope encryption services using pluggable KMS backends
Package crypto provides envelope encryption services using pluggable KMS backends
adapters/local
Package local provides a local in-memory KMS provider for development WARNING: This should NOT be used in production as keys are stored in memory and will be lost on restart
Package local provides a local in-memory KMS provider for development WARNING: This should NOT be used in production as keys are stored in memory and will be lost on restart
adapters/vault
Package vault provides a HashiCorp Vault Transit secrets engine KMS provider
Package vault provides a HashiCorp Vault Transit secrets engine KMS provider
api
factory
Package factory provides factory functions for creating crypto services
Package factory provides factory functions for creating crypto services
examples
logger command
otel command
server command
Package httpclient provides an HTTP client with retry, circuit breaker, and mTLS/TLS support.
Package httpclient provides an HTTP client with retry, circuit breaker, and mTLS/TLS support.
logger
api
otel
api
grpc
Package grpc provides OpenTelemetry instrumentation for gRPC servers and clients.
Package grpc provides OpenTelemetry instrumentation for gRPC servers and clients.
storage
api

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL