Skip to main content

Installation

Add the CLI Proxy API SDK to your Go project:
The SDK requires Go 1.21 or later.

Quick Start Example

Here’s a complete minimal example to embed the proxy in your application:
main.go

Configuration File

Create a basic config.yaml file:
config.yaml
See the Configuration Reference for all available options.

Running Your Application

1

Build your application

Compile your Go application:
2

Create configuration

Ensure your config.yaml file is in the same directory or specify a different path.
3

Run the application

Start your application:
You should see:
4

Test the API

Make a test request:

Understanding the Code

Loading Configuration

The LoadConfig function reads your YAML configuration and returns a *config.Config struct.

Building the Service

The builder pattern allows you to configure the service with:
  • WithConfig: Sets the configuration object
  • WithConfigPath: Sets the path for file watching (automatic reload)
  • Build(): Creates the service instance

Running the Service

The Run method:
  • Starts the HTTP server
  • Initializes authentication providers
  • Starts file watchers for config and auth changes
  • Blocks until the context is cancelled
  • Returns when shutdown is complete

Graceful Shutdown

The example includes graceful shutdown handling:
When the service receives a shutdown signal:
  1. Context is cancelled
  2. HTTP server stops accepting new requests
  3. Existing requests are completed
  4. File watchers are stopped
  5. Authentication providers are cleaned up
  6. Run() returns

Common Patterns

Using Environment Variables

Custom Port Binding

Multiple Services

You can run multiple proxy instances in the same process:

Error Handling

Common errors and how to handle them:

Configuration Errors

Build Errors

Runtime Errors

Next Steps

Embedding Guide

Learn about builder options, hooks, and advanced configuration

Configuration

Explore all configuration options

Advanced Features

Implement custom executors and translators

Access Control

Add custom authentication