Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Using ColdBrew

Table of contents

  1. Project Structure
  2. Defining Your API
  3. Implementing Your Service
  4. Running Your Service
  5. Configuration
  6. Adding Interceptors
  7. What’s Next?

This guide covers how to use ColdBrew after you have created a project. If you haven’t created a project yet, see the Getting Started guide.

Project Structure

A ColdBrew project generated from the cookiecutter template has the following structure:

MyApp/
  proto/              # Protocol buffer definitions
    helloworld.proto
  server/             # gRPC service implementation
    server.go
  main.go             # Entry point
  Makefile             # Build, test, lint, run targets
  Dockerfile           # Production container
  go.mod

Defining Your API

ColdBrew services are defined using Protocol Buffers. Edit your .proto file to add new RPC methods:

service MySvc {
  rpc SayHello (SayHelloRequest) returns (SayHelloResponse) {
    option (google.api.http) = {
      get: "/api/v1/hello"
    };
  }
}

The google.api.http annotation automatically creates a REST endpoint via grpc-gateway.

After editing your proto file, regenerate the Go code:

make gen

Implementing Your Service

Implement the generated gRPC interface in your server/server.go:

func (s *svcNameImpl) SayHello(ctx context.Context, req *pb.SayHelloRequest) (*pb.SayHelloResponse, error) {
    return &pb.SayHelloResponse{
        Message: "Hello " + req.GetName(),
    }, nil
}

Your service struct implements core.CBService, which requires two methods:

  • InitHTTP(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) — Registers HTTP/REST handlers
  • InitGRPC(ctx context.Context, s *grpc.Server) — Registers gRPC handlers

Running Your Service

make run

This starts the service with:

  • gRPC server on port 9090 (default)
  • HTTP gateway on port 9091 (default)
  • Prometheus metrics at /metrics
  • Health check at /healthcheck and /readycheck
  • pprof debug endpoints at /debug/pprof/

Configuration

ColdBrew uses environment variables for configuration. Common settings:

Variable Default Description
GRPC_PORT 9090 gRPC server port
HTTP_PORT 9091 HTTP gateway port
LOG_LEVEL info Log level (debug, info, warn, error)
JSON_LOGS true JSON formatted logs
ENVIRONMENT development Environment name
TRACE_HEADER_NAME X-Trace-Id Header name for trace propagation
NEW_RELIC_APP_NAME   New Relic application name
NEW_RELIC_LICENSE_KEY   New Relic license key
SENTRY_DSN   Sentry DSN for error tracking

Adding Interceptors

ColdBrew comes with a comprehensive set of interceptors pre-configured. To add custom interceptors:

import "github.com/go-coldbrew/interceptors"

func init() {
    interceptors.AddUnaryServerInterceptor(myCustomInterceptor)
}

Interceptor configuration functions must be called during init() — they are not safe for concurrent use.

What’s Next?

  • How-To Guides — Detailed guides for tracing, logging, metrics, error handling, and more
  • Integrations — Setting up New Relic, Prometheus, Sentry, and other integrations
  • Packages — Browse all ColdBrew packages