admin

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package admin serves the admin API of a mock server: a RESTful HTTP server of its own, on its own address, the same for mock servers of every protocol. Package handler holds its units, one per operation; a server answers 501 to the operations its protocol can't do, so the API, and its OpenAPI document, stay the same. With Options.MCP, it serves the operations over MCP too, as tools, which leave out what the server can't do.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Addr is the address the admin API listens on: host:port, :port or a port. Empty is a random local port.
	Addr string

	// MCP serves the admin operations over MCP too: Streamable HTTP at POST /mcp, and stdio with [Server.ServeMCP].
	MCP bool

	// Middlewares wrap every HTTP request of the admin API, the first outermost. They run before the cross-origin
	// check and the routes, and not for MCP over stdio.
	Middlewares []func(http.Handler) http.Handler

	// DocsVersion is the version of Scalar the docs page loads. Empty is the version vlatte pins.
	DocsVersion string

	// Auth are the credentials every HTTP request needs, but those of the probes. The zero value asks for none. They
	// are checked after the middlewares, so one can answer a CORS preflight, which carries none.
	Auth handler.Credentials

	// TLS serves the admin API over HTTPS with its certificates. Nil serves plain HTTP.
	TLS *tls.Config
}

Options configure a Server.

type Server

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

Server is the admin API of a mock server.

func MustNew

func MustNew(opts Options, caps adminapi.Capabilities) *Server

MustNew is like New, but panics on an error.

func New

func New(opts Options, caps adminapi.Capabilities) (*Server, error)

New creates the admin API of the mock server of caps, which needs its Mocks.

func (*Server) Close

func (s *Server) Close() error

Close stops the admin API, and waits for the requests and MCP calls it serves to end, so no admin operation runs, and no connection stays, once it returns. It closes the connections of requests that take longer than a few seconds. A closed server doesn't start again.

func (*Server) ServeMCP

func (s *Server) ServeMCP(ctx context.Context, in io.Reader, out io.Writer) error

ServeMCP serves the admin operations over MCP on in and out, newline-delimited JSON-RPC, as a client that starts the mock server as a process talks to it, until in ends or ctx is done. It needs no Start, and Close waits for the calls it serves. It fails when MCP is off.

func (*Server) Start

func (s *Server) Start() error

Start listens on the server's address and serves the admin API. It starts once: it fails with vlatte.ErrStarted once it started, and with http.ErrServerClosed once it closed. A start that fails to listen closes the server.

func (*Server) URL

func (s *Server) URL() string

URL returns the base URL of the admin API, or "" before it starts.

Directories

Path Synopsis
Package handler holds the admin operations of a mock server, and the units of the admin API that serve them over HTTP.
Package handler holds the admin operations of a mock server, and the units of the admin API that serve them over HTTP.

Jump to

Keyboard shortcuts

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