gframework

module
v1.3.12 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT

README ΒΆ

gframework

gframework is a production-ready Go microservices framework providing essential building blocks for building scalable backend services.

It is designed with best practices, enterprise-grade patterns, and idiomatic Go conventions.

Go Version License

✨ Features

  • 🌐 HTTP Server Echo-based REST API server with preconfigured middleware.

  • πŸ—„οΈ PostgreSQL Integration Connection pooling with pgx/v5 and migration support.

  • πŸ”΄ Redis Client Connection pooling, health checks, and pub/sub messaging.

  • πŸ“¨ Message Streaming Redis Streams-based pub/sub with Watermill integration.

  • πŸ” JWT Authentication JWKS-based token validation middleware.

  • 🎯 Service Runner Graceful lifecycle management for multiple services.

  • πŸ“ Request Logging Structured logging with request-scoped context.

  • βœ… Validation Request validation with go-playground/validator.

  • πŸ“Š Metrics Server Prometheus metrics endpoint built-in.

  • πŸ§ͺ Testing Utilities Testcontainers integration for integration tests.

πŸ“¦ Installation

go get github.com/andyle182810/gframework

πŸš€ Quick Start

package main

import (
    "context"
    "time"

    "github.com/andyle182810/gframework/httpserver"
    "github.com/labstack/echo/v5"
    "github.com/rs/zerolog/log"
)

func main() {
    cfg := &httpserver.Config{
        Host:         "0.0.0.0",
        Port:         8080,
        EnableCors:   true,
        BodyLimit:    "10M",
        ReadTimeout:  30 * time.Second,
        WriteTimeout: 30 * time.Second,
        GracePeriod:  10 * time.Second,
    }

    server := httpserver.New(cfg)

    server.Root.GET("/health", func(c echo.Context) error {
        return c.JSON(200, map[string]string{"status": "ok"})
    })

    if err := server.Run(context.Background()); err != nil {
        log.Fatal().Err(err).Msg("Server failed")
    }
}

πŸ§ͺ Testing

The framework includes testcontainers integration for integration testing:

import (
    "github.com/andyle182810/gframework/testutil"
)

func TestWithPostgres(t *testing.T) {
    container, connString := testutil.SetupPostgresContainer(t)
    defer container.Terminate(context.Background())

    db, err := postgres.New(&postgres.Config{URL: connString})
    // Run tests...
}

Run tests:

go test ./...

⚑ Middleware

The framework includes several built-in middleware:

  • Request Logger - Structured request/response logging
  • Error Handler - Standardized error responses
  • JWKS Auth - JWT token validation with JWKS
  • CORS - Cross-origin resource sharing
  • Body Limit - Request body size limiting

πŸ› οΈ Error Handling

Errors follow Go best practices:

  • All errors are defined as package-level variables
  • Sentinel errors use the Err prefix (e.g., ErrConfigNil)
  • Errors are wrapped with context using fmt.Errorf with %w

πŸ“š Dependencies

Key dependencies:

πŸ’‘ Examples

See the examples directory for complete working examples.

πŸ“¬ Support

For bugs, questions, or feature requests:

πŸ“„ License

gframework is licensed under the MIT License. See the LICENSE file for details.

Directories ΒΆ

Path Synopsis
Package authtoken provides OAuth2 client-credentials token management with automatic caching and refresh.
Package authtoken provides OAuth2 client-credentials token management with automatic caching and refresh.
Package cache provides a generic, type-safe caching layer using Redis.
Package cache provides a generic, type-safe caching layer using Redis.
Package distlock provides Redis-backed distributed locking with two usage modes: fail-hard and fail-silent.
Package distlock provides Redis-backed distributed locking with two usage modes: fail-hard and fail-silent.
Package httpclient provides a generic, type-safe HTTP client for JSON REST APIs.
Package httpclient provides a generic, type-safe HTTP client for JSON REST APIs.
Package httpserver provides an opinionated HTTP server wrapper around Echo v5 with integrated middleware.
Package httpserver provides an opinionated HTTP server wrapper around Echo v5 with integrated middleware.
Package jwks provides a production-ready JWKS (JSON Web Key Set) key function for validating JWTs.
Package jwks provides a production-ready JWKS (JSON Web Key Set) key function for validating JWTs.
Package keycloak provides a Keycloak integration with two complementary clients:
Package keycloak provides a Keycloak integration with two complementary clients:
Package logutil provides log-level string parsing for zerolog and PostgreSQL query tracing.
Package logutil provides log-level string parsing for zerolog and PostgreSQL query tracing.
Package metricserver provides a dedicated HTTP server for operational endpoints: a /status health-check and a /metrics Prometheus scrape endpoint.
Package metricserver provides a dedicated HTTP server for operational endpoints: a /status health-check and a /metrics Prometheus scrape endpoint.
Package middleware provides reusable Echo v5 middleware and context value accessors for common patterns.
Package middleware provides reusable Echo v5 middleware and context value accessors for common patterns.
Package postgres provides a PostgreSQL connection pool factory with built-in support for decimal types, query tracing via zerolog, and configurable session-level timeouts.
Package postgres provides a PostgreSQL connection pool factory with built-in support for decimal types, query tracing via zerolog, and configurable session-level timeouts.
Package redispub provides a Redis Stream publisher using Watermill message bus.
Package redispub provides a Redis Stream publisher using Watermill message bus.
Package redissub provides a Redis Stream subscriber with automatic retry, timeout, and lifecycle management.
Package redissub provides a Redis Stream subscriber with automatic retry, timeout, and lifecycle management.
Package runner provides an application lifecycle manager for coordinated startup and graceful shutdown.
Package runner provides an application lifecycle manager for coordinated startup and graceful shutdown.
Package taskqueue provides a Redis-backed distributed task queue with at-least-once delivery semantics.
Package taskqueue provides a Redis-backed distributed task queue with at-least-once delivery semantics.
Package testutil provides integration-test helpers including Docker container setup, random data generation, context factories, and database utilities for testing gframework applications.
Package testutil provides integration-test helpers including Docker container setup, random data generation, context factories, and database utilities for testing gframework applications.
Package validator provides request validation for REST APIs using go-playground/validator with support for decimal types and JSON-based field naming.
Package validator provides request validation for REST APIs using go-playground/validator with support for decimal types and JSON-based field naming.
Package valkey provides a Valkey/Redis client wrapper with health checking and lifecycle management.
Package valkey provides a Valkey/Redis client wrapper with health checking and lifecycle management.
Package workerpool provides a generic, tick-driven worker pool that repeatedly invokes an Executor on a fixed interval.
Package workerpool provides a generic, tick-driven worker pool that repeatedly invokes an Executor on a fixed interval.

Jump to

Keyboard shortcuts

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