server

package
v0.1.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnableToStartDatabase is returned when the database fails to start.
	ErrUnableToStartDatabase = errors.New("server: error while attempting to start database")
	// ErrUnableToStartEngine is returned when the query engine fails to start.
	ErrUnableToStartEngine = errors.New("server: error while attempting to start engine")
	// ErrUnableToServe is returned when the HTTP server fails for a reason other
	// than a clean shutdown (e.g. the port is already in use).
	ErrUnableToServe = errors.New("server: error while serving HTTP")
	// ErrUnableToStopDatabase is returned when the database fails to stop.
	ErrUnableToStopDatabase = errors.New("server: error while attempting to stop database")
	// ErrUnableToStopEngine is returned when the query engine fails to stop.
	ErrUnableToStopEngine = errors.New("server: error while attempting to stop engine")
	// ErrUnableToStartScheduler is returned when the scheduler fails to start.
	ErrUnableToStartScheduler = errors.New("server: error while attempting to start scheduler")
)

Sentinel errors returned by the server when a component fails to start or stop.

Functions

This section is empty.

Types

type ErrorResponse

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

ErrorResponse is the JSON error body returned to clients: a single human-readable message under "error". The HTTP status code carries the category (4xx client error, 5xx server error), so it is not duplicated in the body. Both SDKs read the "error" field, so that key is part of the contract.

type HandleQueryRequest

type HandleQueryRequest[P float32 | float64] struct {
	Query      string         `json:"query"`
	Parameters map[string][]P `json:"parameters,omitempty"`
}

HandleQueryRequest is the JSON body expected by the query endpoint. It carries the raw query string plus any out-of-band parameters it references. Vector placeholders in the query (e.g. vec:$v) are bound by name from Parameters, so the parser never has to handle large vector literals inline.

type Request

type Request struct {
}

Request is a placeholder for a generic incoming request payload.

type Server

type Server[K ~uint64, P float32 | float64] struct {
	// Config holds the full application configuration.
	Config *config.ConfigSet

	// DB is the underlying data store.
	DB *db.DB[K, P]
	// Engine executes queries against the data store.
	Engine *engine.Engine[K, P]
	// contains filtered or unexported fields
}

Server ties together the HTTP layer, the database, and the query engine. K is the key type used to identify records, and P is the floating-point precision (float32 or float64) used for the values they hold.

func New

func New[K ~uint64, P float32 | float64](config *config.ConfigSet, hasher hash.Hasher[K, string]) (*Server[K, P], error)

New constructs a Server wired up with a database, an engine, and the HTTP routes. The hasher determines how keys are mapped to their string representation for storage and lookup.

func (*Server[K, P]) Start

func (s *Server[K, P]) Start(ctx context.Context) error

Start brings up the database and engine, then serves HTTP requests on the configured port. It blocks until ctx is cancelled (e.g. SIGTERM) or the HTTP server stops on its own, then tears the stack down gracefully: in-flight requests are given ShutdownGrace to finish before the engine and database are stopped. It returns an error if any component fails to start or the HTTP server fails for a reason other than a clean shutdown.

func (*Server[K, P]) Stop

func (s *Server[K, P]) Stop() error

Stop gracefully shuts down the engine and then the database. The engine is stopped first so its workers have drained before DB.Stop reallocates the graph slice; the reverse order would let a running worker dereference a nil graph. It returns an error if the database fails to stop.

Jump to

Keyboard shortcuts

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