go-common

module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT

README

Contributions Welcome coverage Test Lint Go Report Card Total Views Release

Common Backend Framework

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
import (
    "github.com/kittipat1413/go-common/framework/logger"
    "github.com/kittipat1413/go-common/framework/trace"
    // ... other imports
)
  1. Initialize Components Set up the components you need, such as the logger and tracer, in your application's entry point.
func main() {
    // Initialize the logger
    logger := logger.NewDefaultLogger()

    // Initialize the tracer
    endpoint := "localhost:4317"
    tracerProvider, err := trace.InitTracerProvider(ctx, "my-service", &endpoint, trace.ExporterGRPC)
    if err != nil {
      // Handle error
      return
    }
    defer func() {
      if err := tracerProvider.Shutdown(ctx); err != nil {
        // Handle error
      }
    }()

    // ... rest of your application setup
}

Modules and Packages

Logger

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.
Tracer

Implements distributed tracing capabilities to monitor and debug microservices.

  • Features:
    • Integrates with tracing systems like OpenTelemetry.
    • Captures spans and context propagation.
    • Minimal performance overhead.
Error

Standardizes error handling and response formatting.

  • Features:
    • Consistent error formatting and wrapping.
    • Error codes and messages.
    • HTTP status code mapping.
    • Error response generation.
Event Package

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.
Utilities

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.

Directories

Path Synopsis
framework
cache/mocks
Package cache_mocks is a generated GoMock package.
Package cache_mocks is a generated GoMock package.
event/mocks
Package event_handler_mocks is a generated GoMock package.
Package event_handler_mocks is a generated GoMock package.
logger/mocks
Package logger_mocks is a generated GoMock package.
Package logger_mocks is a generated GoMock package.
util
jwt
jwt/mocks
Package jwt_mocks is a generated GoMock package.
Package jwt_mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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