logo
0
0
WeChat Login

Trellis Framework

A pragmatic Go framework for HTTP (Gin) and gRPC services.

Trellis focuses on practical defaults, modular middlewares, and clean configuration.

Features

  • HTTP & gRPC with shared config
  • Middlewares/Interceptors: Timeout, Body Limit, Logging, CORS, PProf, Compression, Validation, Auth, Dedup, Swagger/OpenAPI, Cache
  • Resilience: Rate Limiting (local/redis/hybrid), Circuit Breaker
  • Observability: Prometheus metrics, Trace ID + Request ID
  • Config & Ops: YAML/JSON, defaults/validation, Hot Reload (fsnotify/signals)

Installation

go get trellis.tech/trellis/framework.v0

Quick Start

Minimal HTTP

package main

import (
    "github.com/sirupsen/logrus"
    "trellis.tech/trellis/framework.v0/configs"
    "trellis.tech/trellis/framework.v0/services"
)

func main() {
    cfg := &configs.Config{
        ServiceType:   configs.ServiceTypeHTTP, // or ServiceTypeGRPC
        ServiceConfig: configs.ServiceConfig{Name: "my-service", Address: ":8080"},
        LoggerConfig:  configs.LoggerConfig{Level: logrus.InfoLevel, Formatter: "json"},
    }
    service, err := services.NewWithConfig(cfg)
    if err != nil { panic(err) }
    service.Start2StopWithSignal()
}

Documentation

See:

Note: Core implementations for rate limiting, circuit breaker, and tracing are provided by trellis.tech/trellis/common.v3:

  • Rate Limiting: trellis.tech/trellis/common.v3/middleware/ratelimit
  • Circuit Breaker: trellis.tech/trellis/common.v3/middleware/circuitbreaker
  • Tracing: trellis.tech/trellis/common.v3/middleware/tracing

Package Structure

framework/
├── configs/              # Configuration structures and validation
├── middlewares/          # Middleware components (HTTP & gRPC)
│   ├── httpmw/          # HTTP: timeout, body limit, compression, validation, auth, swagger, cache, ...
│   ├── grpcmw/          # gRPC: timeout, error, logging, auth, cache, deduplication, ...
│   ├── ratelimitmw/     # Rate limiting middleware (uses common.v3/middleware/ratelimit)
│   └── circuitbreakermw/# Circuit breaker middleware (uses common.v3/middleware/circuitbreaker)
├── services/            # Service implementation (HTTP/gRPC)
├── utils/               # Framework-specific utilities
│   ├── errors/          # Error response formatting
│   ├── iputil/          # IP utility functions
│   └── metrics/        # Metrics registry
├── routes/              # Route definitions
├── servers/             # Server registration interface
└── examples/            # Example implementations

Dependencies: This framework uses trellis.tech/trellis/common.v3 for core implementations:

  • Rate limiting, circuit breaker, and tracing are provided by common.v3
  • Redis client configuration is provided by common.v3/clients/redis

Examples

See examples for runnable HTTP Gateway and gRPC servers.

Testing

# Run all tests (excluding examples)
make test

# Run tests with coverage
make test-cover

# Run tests with HTML coverage report
make test-cover-html

License

Copyright © 2025 Henry Huang

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

About

后端服务框架 API: Gin + GraphQL Server: Buf + Protobuf

2.01 MiB
0 forks0 stars2 branches0 TagREADMEGPL-3.0 license
Language
Go99.6%
Makefile0.3%
Shell0.1%
HTML0%