go

module
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: Apache-2.0

README ΒΆ

Common Library for Go

CI Coverage Go Report Card Go Version Reference License GitHub stars

A comprehensive, production-ready Go library providing utilities and wrappers for common development tasks. This library simplifies complex operations while maintaining type safety, performance, and idiomatic Go patterns.

✨ Highlights

  • πŸš€ Production-Ready - Battle-tested in production environments
  • πŸ“¦ Comprehensive - 20+ packages covering common development needs
  • πŸ”’ Type-Safe - Leveraging Go generics for compile-time safety
  • πŸ“š Well-Documented - Extensive documentation and examples for every package
  • ⚑ High Performance - Optimized implementations with minimal overhead
  • πŸ§ͺ Thoroughly Tested - Comprehensive test coverage with integration tests

πŸ“¦ Installation

go get -u github.com/common-library/go

πŸš€ Quick Start

package main

import (
    "fmt"
    "time"
    "net/http"
    "github.com/common-library/go/http"
    "github.com/common-library/go/json"
)

func main() {
    // HTTP request made easy
    response, _ := http.Request(
        "https://api.example.com/data",
        http.MethodGet,
        nil,              // headers
        "",               // body
        10*time.Second,   // timeout
        "", "",           // auth
        nil,              // transport
    )
    
    // Type-safe JSON conversion
    data, _ := json.ConvertFromString[map[string]interface{}](response.Body)
    
    fmt.Println(data)
}

πŸ“š Features

πŸ“ Archive & Compression
  • archive - Archive and compression utilities
    • gzip - Gzip compression and decompression
    • tar - TAR archive creation and extraction
    • zip - ZIP archive operations
☁️ AWS Services
  • AWS - Amazon Web Services integrations
    • DynamoDB - AWS DynamoDB client with simplified operations
    • S3 - Amazon S3 object storage operations
πŸ’» Command Line
πŸ—‚οΈ Data Structures
  • collection - Generic data structures (Deque, Queue)
πŸ—„οΈ Databases

Database - Database clients and utilities

NoSQL & Document Stores
SQL Databases
  • sql - Unified SQL client supporting:
    • Amazon DynamoDB
    • ClickHouse
    • Microsoft SQL Server
    • MySQL
    • Oracle Database
    • PostgreSQL
    • SQLite
ORM & Query Builders
  • ORM - Object-Relational Mapping libraries
    • beego ORM - Beego ORM wrapper
    • ent - Entity framework for Go
    • GORM - Feature-rich ORM library
    • sqlc - Compile-time SQL query generator
    • sqlx - Extensions to database/sql
Database Tools
πŸ“‘ Events & Messaging
πŸ“„ File Operations
  • file - File and directory utilities
🌐 Network & Communication
  • gRPC - Simplified gRPC client and server
  • HTTP - HTTP client and server frameworks
    • Client - HTTP client with timeout and authentication support
    • Echo - Echo v4 web framework wrapper
    • Gin - Gin web framework wrapper
    • Mux - Gorilla Mux router wrapper
  • Socket - TCP/UDP socket communication
    • TCP - TCP client and server with connection pooling
    • UDP - UDP server with async and sync handlers
  • Long Polling - HTTP long polling implementation
πŸ“¦ Data Formats
  • JSON - Type-safe JSON marshaling with generics
☸️ Kubernetes
πŸ”’ Concurrency & Synchronization
  • lock - Mutex utilities with key-based locking
πŸ“ Logging
  • log - Logging utilities
    • klog - Kubernetes-style structured logging
    • slog - Structured logging with context
πŸ” Security
πŸ’Ύ Storage
  • storage - Object storage clients
    • MinIO - S3-compatible object storage client
πŸ› οΈ Utilities
  • utility - Runtime introspection, type info, and CIDR utilities
πŸ§ͺ Testing
  • testutil - Testing utilities and container image constants

πŸ§ͺ Testing & Development

Running Tests

Run all tests with coverage:

go clean -testcache && go test -cover ./...
Coverage Reports

Generate coverage profile:

go clean -testcache && go test -coverprofile=coverage.out -cover ./...

Convert to HTML report:

go tool cover -html=./coverage.out -o ./coverage.html

View in browser:

open coverage.html  # macOS
xdg-open coverage.html  # Linux

πŸ”§ Development Guides

Working with Ent ORM

Add a new entity schema (e.g., User):

# Install ent CLI
go get entgo.io/ent/cmd/ent

# Create new schema
go run entgo.io/ent/cmd/ent new --target ./database/orm/ent/schema User

# Edit schema file
vim ./database/orm/ent/schema/user.go

# Generate code with upsert support
go run entgo.io/ent/cmd/ent generate --feature sql/upsert ./database/orm/ent/schema
Working with sqlc

Configure and generate type-safe SQL code:

# Install sqlc
go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.27.0

# Add queries to ./database/orm/sqlc/queries
# Add schemas to ./database/orm/sqlc/schema
# Configure ./database/orm/sqlc/sqlc.json

# Generate Go code
sqlc generate --file ./database/orm/sqlc/sqlc.json
Working with gRPC

Create and implement gRPC services:

# Install protoc compiler and plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.10
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1

# Download protoc (example for Linux)
wget https://github.com/protocolbuffers/protobuf/releases/download/v32.1/protoc-32.1-linux-x86_64.zip
unzip protoc-32.1-linux-x86_64.zip -d protoc/

# Create your .proto file (see grpc/sample/sample.proto for example)
# Generate Go code
protoc/bin/protoc \
  --go_out=. \
  --go_opt=paths=source_relative \
  --go-grpc_out=. \
  --go-grpc_opt=paths=source_relative \
  grpc/sample/sample.proto

Implementation Steps:

  1. Create .proto file with service definition (example)
  2. Generate Go code using protoc
  3. Implement the service interface (example)
  4. Register service with gRPC server (implement RegisterServer method)
  5. Write tests (example)

πŸ“– Documentation

Each package includes comprehensive documentation:

  • Package-level godoc comments
  • Function/method documentation with examples
  • README.md files for complex packages
  • Integration test examples

Browse the pkg.go.dev documentation or explore individual package directories.

🀝 Contributing

Contributions are welcome! Please ensure:

  • All tests pass: go test ./...
  • Code is formatted: go fmt ./...
  • Linting passes: golangci-lint run
  • Documentation is updated
  • Examples are provided for new features

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

⭐ Support

If you find this library helpful, please consider giving it a star on GitHub!

πŸ“ž Contact & Support

Directories ΒΆ

Path Synopsis
archive
gzip
Package gzip provides utilities for creating and extracting gzip compressed files.
Package gzip provides utilities for creating and extracting gzip compressed files.
tar
Package tar provides utilities for creating and extracting tar.gz archives.
Package tar provides utilities for creating and extracting tar.gz archives.
zip
Package zip provides utilities for creating and extracting zip archives.
Package zip provides utilities for creating and extracting zip archives.
aws
dynamodb
Package dynamodb provides utilities for working with AWS DynamoDB.
Package dynamodb provides utilities for working with AWS DynamoDB.
s3
Package s3 provides utilities for working with AWS S3 (Simple Storage Service).
Package s3 provides utilities for working with AWS S3 (Simple Storage Service).
Package collection provides thread-safe data structure implementations.
Package collection provides thread-safe data structure implementations.
command-line
arguments
Package arguments provides utilities for accessing command-line arguments.
Package arguments provides utilities for accessing command-line arguments.
flags
Package flags provides utilities for parsing and accessing command-line flags.
Package flags provides utilities for parsing and accessing command-line flags.
database
elasticsearch
Package elasticsearch provides a unified interface for Elasticsearch clients across multiple versions.
Package elasticsearch provides a unified interface for Elasticsearch clients across multiple versions.
elasticsearch/internal/eslock
Package eslock provides a global lock for elasticsearch client initialization to prevent data races in the underlying elastictransport library.
Package eslock provides a global lock for elasticsearch client initialization to prevent data races in the underlying elastictransport library.
elasticsearch/testutil
Package testutil provides test utilities for Elasticsearch client testing.
Package testutil provides test utilities for Elasticsearch client testing.
elasticsearch/v7
Package v7 provides Elasticsearch version 7 client implementation.
Package v7 provides Elasticsearch version 7 client implementation.
elasticsearch/v8
Package v8 provides Elasticsearch version 8 client implementation.
Package v8 provides Elasticsearch version 8 client implementation.
elasticsearch/v9
Package v9 provides Elasticsearch version 9 client implementation.
Package v9 provides Elasticsearch version 9 client implementation.
mongodb
Package mongodb provides a MongoDB client wrapper with simplified operations and automatic reconnection.
Package mongodb provides a MongoDB client wrapper with simplified operations and automatic reconnection.
prometheus/client
Package client provides a wrapper around the official Prometheus Go client library for querying Prometheus metrics with support for basic authentication, bearer token authentication, and PromQL queries.
Package client provides a wrapper around the official Prometheus Go client library for querying Prometheus metrics with support for basic authentication, bearer token authentication, and PromQL queries.
prometheus/exporter
Package exporter provides a framework for creating Prometheus exporters that expose custom metrics through an HTTP endpoint.
Package exporter provides a framework for creating Prometheus exporters that expose custom metrics through an HTTP endpoint.
redis
Package redis provides a Redis client implementation with connection pooling.
Package redis provides a Redis client implementation with connection pooling.
sql
Package sql provides a unified SQL database client supporting multiple database drivers.
Package sql provides a unified SQL database client supporting multiple database drivers.
event
cloudevents
Package cloudevents provides CloudEvents client and server implementations.
Package cloudevents provides CloudEvents client and server implementations.
Package file provides utilities for file and directory operations.
Package file provides utilities for file and directory operations.
Package grpc provides simplified gRPC client and server utilities.
Package grpc provides simplified gRPC client and server utilities.
sample
Package sample provides sample grpc interface.
Package sample provides sample grpc interface.
Package http provides simplified HTTP client and server utilities.
Package http provides simplified HTTP client and server utilities.
echo
Package echo provides a simplified wrapper around the Echo web framework.
Package echo provides a simplified wrapper around the Echo web framework.
gin
Package gin provides a simplified wrapper around the Gin web framework.
Package gin provides a simplified wrapper around the Gin web framework.
mux
Package http provides simplified HTTP client and server utilities.
Package http provides simplified HTTP client and server utilities.
Package json provides utilities for converting between JSON and Go structs.
Package json provides utilities for converting between JSON and Go structs.
kubernetes
resource/client
Package client provides Kubernetes REST client utilities for resource management.
Package client provides Kubernetes REST client utilities for resource management.
Package lock provides mutex implementations for synchronization.
Package lock provides mutex implementations for synchronization.
log
klog
Package klog provides wrapper functions for Kubernetes klog logging.
Package klog provides wrapper functions for Kubernetes klog logging.
slog
Package slog provides structured logging with asynchronous output and flexible configuration.
Package slog provides structured logging with asynchronous output and flexible configuration.
Package long_polling provides HTTP long polling server and client implementations.
Package long_polling provides HTTP long polling server and client implementations.
security
crypto/dsa
Package dsa provides DSA digital signature cryptography.
Package dsa provides DSA digital signature cryptography.
crypto/ecdsa
Package ecdsa provides ECDSA digital signature cryptography.
Package ecdsa provides ECDSA digital signature cryptography.
crypto/ed25519
Package ed25519 provides Ed25519 digital signature cryptography.
Package ed25519 provides Ed25519 digital signature cryptography.
crypto/rsa
Package rsa provides RSA public-key cryptography.
Package rsa provides RSA public-key cryptography.
tcp
Package tcp provides TCP socket client and server implementations.
Package tcp provides TCP socket client and server implementations.
udp
Package udp provides UDP socket client and server implementations.
Package udp provides UDP socket client and server implementations.
storage
minio
Package minio provides MinIO object storage client.
Package minio provides MinIO object storage client.
Package testutil provides testing utilities and container image constants.
Package testutil provides testing utilities and container image constants.
Package utility provides general-purpose utility functions.
Package utility provides general-purpose utility functions.

Jump to

Keyboard shortcuts

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