api

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(cfg *ServerConfig) gin.HandlerFunc

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

Types

type APIHandlers

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

APIHandlers contains the handlers for API endpoints. It holds a pool of clients to interact with the backend service.

func NewAPIHandlers

func NewAPIHandlers(cliClients []*client.Client, debug bool) *APIHandlers

NewAPIHandlers creates a new API handlers instance. It takes a slice of clients and a debug flag as input.

func (*APIHandlers) ChatCompletions

func (h *APIHandlers) ChatCompletions(c *gin.Context)

ChatCompletions handles the /v1/chat/completions endpoint. It determines whether the request is for a streaming or non-streaming response and calls the appropriate handler.

func (*APIHandlers) Models

func (h *APIHandlers) Models(c *gin.Context)

Models handles the /v1/models endpoint. It returns a hardcoded list of available AI models.

type ErrorDetail

type ErrorDetail struct {
	// A human-readable message providing more details about the error.
	Message string `json:"message"`
	// The type of error that occurred (e.g., "invalid_request_error").
	Type string `json:"type"`
	// A short code identifying the error, if applicable.
	Code string `json:"code,omitempty"`
}

ErrorDetail provides specific information about an error that occurred. It includes a human-readable message, an error type, and an optional error code.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse represents a standard error response format for the API. It contains a single ErrorDetail field.

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(config *ServerConfig, cliClients []*client.Client) *Server

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

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.

func (*Server) Stop

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

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

type ServerConfig

type ServerConfig struct {
	// Port is the port number the server will listen on.
	Port string
	// Debug enables or disables debug mode for the server and Gin.
	Debug bool
	// ApiKeys is a list of valid API keys for authentication.
	ApiKeys []string
}

ServerConfig contains the configuration for the API server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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