class-server

command module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 15 Imported by: 0

README ΒΆ

go-server-with-otel πŸš€

A powerful and flexible template for building Go HTTP + GRPC servers with full OpenTelemetry (OTEL) support. Bootstrapped with the go-app framework to provide all the bells and whistles right out of the box. Ideal for rapidly creating production-ready microservices.

Check out the go-app framework for more detail there.

🌟 Features

  • πŸ“ˆ OpenTelemetry (OTEL) Metrics & Traces – Comprehensive observability with built-in support for metrics and traces.
  • πŸ“ Logging with Zerolog – High-performance structured logging with zerolog for ultra-fast, leveled logging.
  • πŸ’¬ GRPC + GRPC-Gateway – Supports RESTful JSON APIs alongside gRPC with auto-generated Swagger (OpenAPI2) specs.
  • 🌐 HTTP and GRPC Middleware – Flexible middleware support for HTTP and GRPC to enhance request handling, authentication, and observability.
  • πŸ“¦ Multi-Arch Builds – Robust Makefile that supports building for multiple architectures (amd64, arm64, etc.).
  • 🐳 Docker Image Generation – Easily build Docker images using make docker.
  • πŸ“œ Config Schema Generation – Automatically generate JSON schemas for configuration validation.
  • πŸ“ Proto Compilation – Seamlessly compile .proto files with make proto.
  • πŸ”„ Project Renaming – Easily rename your project using make rename NAME=your.gitremote.com/pathto/repo.
  • πŸ“¦ Helm Chart – Deploy your application with Kubernetes using the provided Helm chart.
  • πŸ€– Gitea CI Integration – Out-of-the-box Gitea CI pipeline configuration with .gitea/workflows/ci.yaml.
  • βš™οΈ Expandable Configuration – Extend your app-specific configuration with go-app's built-in logging, HTTP, and GRPC config support.

πŸ“š Getting Started

  1. Install tools:

    • Install make, protoc, and go using brew, apt, etc..
    • Install protoc plugins (provided in go.mod tool()):
      • go get -v tool && go install -v tool
  2. Rename your package:

    make rename NAME=my.gitremote.com/pathto/repo
    
  3. Review the config struct: Update and customize your app-specific configuration. This merges with go-app's configuration, providing logging, HTTP, and GRPC config for free.

  4. Generate a new JSON schema:

    make schema
    
    • Ensure your structs have yaml and json tags.
    • With the yaml-language-server LSP plugin, the schema will be auto-detected in your config.yaml.
  5. Compile proto files:

    make proto
    
    • Add paths under proto/ as necessary.
  6. Implement your application logic.

  7. Update Gitea CI configuration: Modify parameters in .gitea/workflows/ci.yaml as needed.

  8. Tag your release: git tag v0.1.0 and push git push --tags


πŸ“‚ Project Structure

  • proto/ - Protobuf definitions and generated files.
  • api/ - Auto-generated code for proto, grpc-gateway, and OpenAPI2 spec
  • pkg/config/ - Custom config, merged with go-app configuration
  • pkg/demo(http|grpc)/ - HTTP and GRPC server implementations
  • helm/ - Helm chart for deploying your application to Kubernetes.
  • .gitea/workflows/ - CI pipelines for automated builds and tests.

πŸ”₯ Ready to build something awesome? Let's go! πŸŽ‰

Documentation ΒΆ

Overview ΒΆ

This template contains a simple app with OTEL bootstrap that will create an HTTP server configured by environment that exports spans and metrics to an OTEL collector if configured to do so. Will also stand up a prometheus metrics endpoint.

Configuration and logger stored in context Reference implementation of the provided packages

Directories ΒΆ

Path Synopsis
api
class/v1alpha1
Package class is a reverse proxy.
Package class is a reverse proxy.
demo/app/v1alpha1
Package demo is a reverse proxy.
Package demo is a reverse proxy.
pkg
classgrpc
Package classgrpc provides demonstrative rpc implementation for class server TODO: Move font and text to ClassServiceOpts in New() and use
Package classgrpc provides demonstrative rpc implementation for class server TODO: Move font and text to ClassServiceOpts in New() and use
config
This serves as a reference sample configuration to show how to merge custom config fields into go-app configuration
This serves as a reference sample configuration to show how to merge custom config fields into go-app configuration

Jump to

Keyboard shortcuts

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