api

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package api provides the HTTP API for Vision management and MCP proxying.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(allowedOrigins []string) func(http.Handler) http.Handler

CORSMiddleware adds CORS headers for the management UI.

func Chain

func Chain(handler http.Handler, middlewares ...func(http.Handler) http.Handler) http.Handler

Chain applies middlewares in order (first to last).

func ContentTypeMiddleware

func ContentTypeMiddleware(next http.Handler) http.Handler

ContentTypeMiddleware ensures JSON content type for API responses.

func LoggingMiddleware

func LoggingMiddleware(logger *slog.Logger) func(http.Handler) http.Handler

LoggingMiddleware logs HTTP requests with method, path, status, and duration.

func RecoveryMiddleware

func RecoveryMiddleware(logger *slog.Logger) func(http.Handler) http.Handler

RecoveryMiddleware recovers from panics and returns a 500 error.

Types

type APIResponse

type APIResponse struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

APIResponse wraps API responses with consistent structure.

type AddServerRequest

type AddServerRequest struct {
	Name   string              `json:"name"`
	Config config.ServerConfig `json:"config"`
}

AddServerRequest is the request body for adding a server.

type Handlers

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

Handlers provides HTTP handlers for the management API.

func NewHandlers

func NewHandlers(registry *server.Registry, cfg *config.Config) *Handlers

NewHandlers creates a new Handlers instance.

func (*Handlers) AddServerHandler

func (h *Handlers) AddServerHandler(w http.ResponseWriter, r *http.Request)

AddServerHandler adds a new server to the registry. POST /api/v1/servers

func (*Handlers) DeleteServerHandler

func (h *Handlers) DeleteServerHandler(w http.ResponseWriter, r *http.Request, name string)

DeleteServerHandler removes a server from the registry. DELETE /api/v1/servers/{name}

func (*Handlers) GetServerHandler

func (h *Handlers) GetServerHandler(w http.ResponseWriter, r *http.Request, name string)

GetServerHandler returns a specific server by name. GET /api/v1/servers/{name}

func (*Handlers) HealthHandler

func (h *Handlers) HealthHandler(w http.ResponseWriter, r *http.Request)

HealthHandler returns detailed health status. GET /health

func (*Handlers) HealthzHandler

func (h *Handlers) HealthzHandler(w http.ResponseWriter, r *http.Request)

HealthzHandler returns 200 OK if the service is alive (liveness probe). GET /healthz

func (*Handlers) ListServersHandler

func (h *Handlers) ListServersHandler(w http.ResponseWriter, r *http.Request)

ListServersHandler returns all registered servers. GET /api/v1/servers

func (*Handlers) ReadyHandler

func (h *Handlers) ReadyHandler(w http.ResponseWriter, r *http.Request)

ReadyHandler returns 200 OK if the service is ready to accept traffic. GET /ready

func (*Handlers) RestartServerHandler

func (h *Handlers) RestartServerHandler(w http.ResponseWriter, r *http.Request, name string)

RestartServerHandler restarts a server. POST /api/v1/servers/{name}/restart

func (*Handlers) StartServerHandler

func (h *Handlers) StartServerHandler(w http.ResponseWriter, r *http.Request, name string)

StartServerHandler starts a server. POST /api/v1/servers/{name}/start

func (*Handlers) StopServerHandler

func (h *Handlers) StopServerHandler(w http.ResponseWriter, r *http.Request, name string)

StopServerHandler stops a server. POST /api/v1/servers/{name}/stop

func (*Handlers) UpdateServerHandler

func (h *Handlers) UpdateServerHandler(w http.ResponseWriter, r *http.Request, name string)

UpdateServerHandler updates an existing server's configuration. PUT /api/v1/servers/{name}

type HealthResponse

type HealthResponse struct {
	Status   string                `json:"status"`
	Uptime   string                `json:"uptime"`
	Registry server.RegistryStatus `json:"registry"`
}

HealthResponse is the detailed health status response.

type Server

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

Server is the management API HTTP server.

func NewServer

func NewServer(cfg ServerConfig) *Server

NewServer creates a new management API server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the HTTP handler for the server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(addr string) error

ListenAndServe starts the HTTP server on the given address.

type ServerConfig

type ServerConfig struct {
	Registry       *server.Registry
	Config         *config.Config
	Logger         *slog.Logger
	AllowedOrigins []string // CORS allowed origins, use ["*"] for all
}

ServerConfig configures the API server.

type UpdateServerRequest

type UpdateServerRequest struct {
	Config config.ServerConfig `json:"config"`
}

UpdateServerRequest is the request body for updating a server.

Jump to

Keyboard shortcuts

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