api

package
v5.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package api provides the HTTP API server implementation for the CLI Proxy API. It includes the main server struct, routing setup, middleware for CORS and authentication, and integration with various AI API handlers (OpenAI, Claude, Gemini). The server supports hot-reloading of clients and configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg *config.Config) gin.HandlerFunc

AuthMiddleware returns a Gin middleware handler that authenticates requests using API keys. If no API keys are configured, it allows all requests.

Parameters:

  • cfg: The server configuration containing API keys

Returns:

  • gin.HandlerFunc: The authentication middleware handler

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the main API server. It encapsulates the Gin engine, HTTP server, handlers, and configuration.

func NewServer

func NewServer(cfg *config.Config, cliClients []interfaces.Client, configFilePath string) *Server

NewServer creates and initializes a new API server instance. It sets up the Gin engine, middleware, routes, and handlers.

Parameters:

  • cfg: The server configuration
  • cliClients: A slice of AI service clients

Returns:

  • *Server: A new server instance

func (*Server) Start

func (s *Server) Start() error

Start begins listening for and serving HTTP requests. It's a blocking call and will only return on an unrecoverable error.

Returns:

  • error: An error if the server fails to start

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully shuts down the API server without interrupting any active connections.

Parameters:

  • ctx: The context for graceful shutdown

Returns:

  • error: An error if the server fails to stop

func (*Server) UpdateClients

func (s *Server) UpdateClients(clients map[string]interfaces.Client, cfg *config.Config)

UpdateClients updates the server's client list and configuration. This method is called when the configuration or authentication tokens change.

Parameters:

  • clients: The new slice of AI service clients
  • cfg: The new application configuration

Directories

Path Synopsis
Package handlers provides core API handler functionality for the CLI Proxy API server.
Package handlers provides core API handler functionality for the CLI Proxy API server.
claude
Package claude provides HTTP handlers for Claude API code-related functionality.
Package claude provides HTTP handlers for Claude API code-related functionality.
gemini
Package gemini provides HTTP handlers for Gemini CLI API functionality.
Package gemini provides HTTP handlers for Gemini CLI API functionality.
management
Package management provides the management API handlers and middleware for configuring the server and managing auth files.
Package management provides the management API handlers and middleware for configuring the server and managing auth files.
openai
Package openai provides HTTP handlers for OpenAI API endpoints.
Package openai provides HTTP handlers for OpenAI API endpoints.
Package middleware provides HTTP middleware components for the CLI Proxy API server.
Package middleware provides HTTP middleware components for the CLI Proxy API server.

Jump to

Keyboard shortcuts

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