server

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2025 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package server implements the HTTP server and routing logic for the Hapax LLM service. It provides endpoints for LLM completions, health checks, and Prometheus metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

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

Router handles HTTP routing and middleware configuration. It sets up all endpoints and applies common middleware to requests.

func NewRouter

func NewRouter(llm gollm.LLM, cfg *config.Config, logger *zap.Logger) *Router

NewRouter creates a new router with all endpoints configured. It: 1. Sets up common middleware (request ID, timing, panic recovery, CORS) 2. Configures the completion endpoint for LLM requests 3. Adds health check endpoint for container orchestration 4. Adds metrics endpoint for Prometheus monitoring

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements the http.Handler interface for the router. This allows the router to be used directly with the standard library's HTTP server.

type Server

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

Server represents the HTTP server instance. It wraps the standard library's http.Server with our configuration. The running boolean tracks whether the server is operational, while the mu mutex protects concurrent access to this state. This ensures that multiple goroutines do not interfere with each other when checking or updating the server's status.

func NewServer

func NewServer(configPath string, logger *zap.Logger) (*Server, error)

NewServer creates a new server with the specified configuration and handler. It configures timeouts and limits based on the provided configuration.

func NewServerWithConfig added in v0.0.16

func NewServerWithConfig(cfg config.Watcher, llm gollm.LLM, logger *zap.Logger) (*Server, error)

NewServerWithConfig for testing now takes care of the LLM

func (*Server) Start

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

Start begins serving HTTP requests and blocks until shutdown. It handles graceful shutdown when the context is cancelled, ensuring that all connections are properly closed before exiting.

Directories

Path Synopsis
Package handlers provides HTTP handlers for the Hapax server.
Package handlers provides HTTP handlers for the Hapax server.
Package middleware provides various middleware functions for HTTP handlers.
Package middleware provides various middleware functions for HTTP handlers.
Package processing provides request processing and response formatting for LLM interactions.
Package processing provides request processing and response formatting for LLM interactions.
Package routing provides dynamic HTTP routing with versioning and health checks.
Package routing provides dynamic HTTP routing with versioning and health checks.

Jump to

Keyboard shortcuts

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