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 ¶
- func AuthMiddleware(manager *sdkaccess.Manager) gin.HandlerFunc
- type Server
- type ServerOption
- func WithEngineConfigurator(fn func(*gin.Engine)) ServerOption
- func WithKeepAliveEndpoint(timeout time.Duration, onTimeout func()) ServerOption
- func WithLocalManagementPassword(password string) ServerOption
- func WithMiddleware(mw ...gin.HandlerFunc) ServerOption
- func WithRequestLoggerFactory(factory func(*config.Config, string) logging.RequestLogger) ServerOption
- func WithRouterConfigurator(fn func(*gin.Engine, *handlers.BaseAPIHandler, *config.Config)) ServerOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(manager *sdkaccess.Manager) gin.HandlerFunc
AuthMiddleware returns a Gin middleware handler that authenticates requests using the configured authentication providers. When no providers are available, it allows all requests (legacy behaviour).
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, authManager *auth.Manager, accessManager *sdkaccess.Manager, configFilePath string, opts ...ServerOption) *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
- authManager: core runtime auth manager
- accessManager: request authentication manager
Returns:
- *Server: A new server instance
func (*Server) Start ¶
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 ¶
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 ¶
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
type ServerOption ¶
type ServerOption func(*serverOptionConfig)
ServerOption customises HTTP server construction.
func WithEngineConfigurator ¶
func WithEngineConfigurator(fn func(*gin.Engine)) ServerOption
WithEngineConfigurator allows callers to mutate the Gin engine prior to middleware setup.
func WithKeepAliveEndpoint ¶ added in v6.0.4
func WithKeepAliveEndpoint(timeout time.Duration, onTimeout func()) ServerOption
WithKeepAliveEndpoint enables a keep-alive endpoint with the provided timeout and callback.
func WithLocalManagementPassword ¶ added in v6.0.1
func WithLocalManagementPassword(password string) ServerOption
WithLocalManagementPassword stores a runtime-only management password accepted for localhost requests.
func WithMiddleware ¶
func WithMiddleware(mw ...gin.HandlerFunc) ServerOption
WithMiddleware appends additional Gin middleware during server construction.
func WithRequestLoggerFactory ¶
func WithRequestLoggerFactory(factory func(*config.Config, string) logging.RequestLogger) ServerOption
WithRequestLoggerFactory customises request logger creation.
func WithRouterConfigurator ¶
func WithRouterConfigurator(fn func(*gin.Engine, *handlers.BaseAPIHandler, *config.Config)) ServerOption
WithRouterConfigurator appends a callback after default routes are registered.
Directories
¶
| Path | Synopsis |
|---|---|
|
handlers
|
|
|
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. |
|
Package middleware provides HTTP middleware components for the CLI Proxy API server.
|
Package middleware provides HTTP middleware components for the CLI Proxy API server. |