Common Backend Framework

Contributions Welcome coverage Test Lint Go Report Card Release

Welcome to the Common Backend Framework repository! This project provides a collection of utilities, libraries, and frameworks designed to standardize and streamline the development of backend API services within our organization.

Introduction

This repository serves as a central codebase for common functionalities and utilities used across various backend API projects. By consolidating shared code, we aim to:

  • Promote consistency and code standardization.

  • Reduce duplication of effort.

  • Facilitate easier maintenance and updates.

  • Accelerate development by providing ready-to-use components.

Installation

Include the framework in your project by adding it to your go.mod file:

go get github.com/kittipat1413/go-common

Getting Started

  1. Import the Framework

  1. Initialize Components Set up the components you need, such as the logger and tracer, in your application's entry point.

Example Project

Looking for a real-world implementation?

  • Check out the 🎟️ Ticket Reservation System, a clean-architecture-based backend service that demonstrates how to integrate and use the go-common framework across all layers — config, logging, tracing, error handling, HTTP handlers, use cases, and repositories.

Modules and Packages

Provides a structured, context-aware logging interface using logrus. Designed for both development and production environments.

  • Features:

    • Configurable log levels.

    • Structured logging with fields.

    • Context propagation for tracing (trace_id, span_id).

    • Flexible output destinations (stdout, files, etc.).

    • No-op logger for testing.

Implements distributed tracing capabilities to monitor and debug microservices.

  • Features:

    • Integrates with tracing systems like OpenTelemetry.

    • Captures spans and context propagation.

    • Minimal performance overhead.

Standardizes error handling and response formatting.

  • Features:

    • Consistent error formatting and wrapping.

    • Error codes and messages.

    • HTTP status code mapping.

    • Error response generation.

Handles event-driven workflows, including message parsing and callback mechanisms.

  • Features:

    • Integration with HTTP frameworks (like Gin).

    • Defining and processing event messages with flexible, user-defined payload types.

    • Generic payload support with Go generics.

A collection of helper functions and common utilities.

  • Features:

    • Date and time parsing.

    • String manipulation.

    • Configuration loading (e.g., from environment variables, config files).

    • etc.

License

This project is licensed under the MIT License.

Last updated