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 ¶
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 ¶
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.