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 basicconfig.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
LoadConfig function reads your YAML configuration and returns a *config.Config struct.
Building the Service
WithConfig: Sets the configuration objectWithConfigPath: Sets the path for file watching (automatic reload)Build(): Creates the service instance
Running the Service
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:- Context is cancelled
- HTTP server stops accepting new requests
- Existing requests are completed
- File watchers are stopped
- Authentication providers are cleaned up
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