Documentation
¶
Index ¶
- Variables
- func InitLogger(exitOnFatal bool)
- func ReadJSON(r io.Reader, v interface{}) interface{}
- func SendJSON(w http.ResponseWriter, v interface{})
- func SendJSONWithStatus(w http.ResponseWriter, v interface{}, s int)
- func SendStatus(w http.ResponseWriter, s int)
- type Authorizer
- type HTTPContext
- func (ctx *HTTPContext) GetAttribute(key string) interface{}
- func (ctx *HTTPContext) GetParam(p string) string
- func (ctx *HTTPContext) GetQueryParam(p string) string
- func (ctx *HTTPContext) SendJSON(v interface{})
- func (ctx *HTTPContext) SendJSONWithStatus(v interface{}, s int)
- func (ctx *HTTPContext) SendStatus(s int)
- func (ctx *HTTPContext) SetAttribute(key string, attr interface{})
- type HTTPInterceptor
- type HealthcheckController
- type IHttpController
- type MCP
- type MCPConfig
- type MCPResult
- type MCPTool
- type OpenAPIConfig
- type OpenAPISchemaProvider
- type RestRouter
- func (r *RestRouter) Delete(path string, handle func(HTTPContext), v interface{}, ...) *Route
- func (r *RestRouter) Get(path string, handle func(HTTPContext), interceptors ...HTTPInterceptor) *Route
- func (r *RestRouter) Post(path string, handle func(HTTPContext), v interface{}, ...) *Route
- func (r *RestRouter) Put(path string, handle func(HTTPContext), v interface{}, ...) *Route
- type Route
- func (rt *Route) Authorize(a Authorizer) *Route
- func (rt *Route) Deprecated() *Route
- func (rt *Route) Description(s string) *Route
- func (rt *Route) ExcludeFromMCP() *Route
- func (rt *Route) ExcludeFromSpec() *Route
- func (rt *Route) Header(name, typ string, required bool, description string) *Route
- func (rt *Route) IncludeInMCP() *Route
- func (rt *Route) MCPTool(name string) *Route
- func (rt *Route) Param(name, typ, description string) *Route
- func (rt *Route) Query(name, typ string, required bool, description string) *Route
- func (rt *Route) Returns(status int, v interface{}, description string) *Route
- func (rt *Route) Summary(s string) *Route
- func (rt *Route) Tags(t ...string) *Route
- type Router
- type Server
- func (s *Server) AutoMigrate(models ...interface{})
- func (s *Server) GetOpenAPISpec() []byte
- func (s *Server) Start()
- func (s *Server) UseHealthcheck()
- func (s *Server) UseInMemoryDB(debugMode bool)
- func (s *Server) UseMCP(cfg MCPConfig) *MCP
- func (s *Server) UseOpenAPI(cfg OpenAPIConfig)
- func (s *Server) UsePostgresDB(debugMode bool)
Constants ¶
This section is empty.
Variables ¶
var ( ErrMCPNotReady = errors.New("requiem: MCP endpoint is not loaded yet") )
var Logger *logmatic.Logger
Logger provides application-wide logging
Functions ¶
func InitLogger ¶
func InitLogger(exitOnFatal bool)
InitLogger initializes the application-wide logger
func SendJSON ¶
func SendJSON(w http.ResponseWriter, v interface{})
SendJSON converts the given interface into JSON and writes to the provided stream.
func SendJSONWithStatus ¶ added in v0.5.1
func SendJSONWithStatus(w http.ResponseWriter, v interface{}, s int)
SendJSONWithStatus writes a JSON response body to the provided stream, along with the specified status code.
func SendStatus ¶
func SendStatus(w http.ResponseWriter, s int)
SendStatus writes the given HTTP status code into the provided response stream.
Types ¶
type Authorizer ¶ added in v0.9.2
type Authorizer func(ctx HTTPContext) bool
Authorizer reports whether an already-authenticated caller may use a route. It is a pure predicate: it reads identity from the context (set by MCPConfig.Authenticate) and must not write to the response.
type HTTPContext ¶
type HTTPContext struct {
Response http.ResponseWriter
Request *http.Request
Body interface{}
// contains filtered or unexported fields
}
HTTPContext provides utility functions for HTTP requests/responses
func (*HTTPContext) GetAttribute ¶
func (ctx *HTTPContext) GetAttribute(key string) interface{}
GetAttribute returns the context-scoped value for the given key
func (*HTTPContext) GetParam ¶
func (ctx *HTTPContext) GetParam(p string) string
GetParam obtains the given parameter key from the request parameters.
func (*HTTPContext) GetQueryParam ¶ added in v0.6.2
func (ctx *HTTPContext) GetQueryParam(p string) string
GetQueryParam obtains the given query parameter from the request URL.
func (*HTTPContext) SendJSON ¶
func (ctx *HTTPContext) SendJSON(v interface{})
SendJSON converts the given interface into JSON and writes to the response.
func (*HTTPContext) SendJSONWithStatus ¶ added in v0.5.1
func (ctx *HTTPContext) SendJSONWithStatus(v interface{}, s int)
SendJSONWithStatus writes a JSON response body to the response, along with the specified status code.
func (*HTTPContext) SendStatus ¶
func (ctx *HTTPContext) SendStatus(s int)
SendStatus writes the given HTTP status code into the response.
func (*HTTPContext) SetAttribute ¶
func (ctx *HTTPContext) SetAttribute(key string, attr interface{})
SetAttribute sets the context-scoped value for the given key
type HTTPInterceptor ¶
type HTTPInterceptor func(ctx HTTPContext) bool
HTTPInterceptor allows for pre-processing request handlers ex. an authentication interceptor could verify a user session
type HealthcheckController ¶ added in v0.6.0
type HealthcheckController struct {
}
func (HealthcheckController) Load ¶ added in v0.6.0
func (c HealthcheckController) Load(router *Router)
type IHttpController ¶
type IHttpController interface {
Load(router *Router)
}
IHttpController represents a REST API that can be loaded into a router
type MCP ¶ added in v0.10.0
type MCP struct {
// contains filtered or unexported fields
}
MCP gives in-process access to the tools the MCP endpoint serves, as seen by one caller.
type MCPConfig ¶ added in v0.9.0
type MCPConfig struct {
// Name is the server name reported to MCP clients (serverInfo.name).
Name string
// Version is the server version reported to MCP clients (serverInfo.version).
Version string
// Instructions is optional free-form guidance returned during initialize.
Instructions string
// Path overrides the endpoint path. Defaults to the API's common route prefix
// plus "/mcp" (e.g. "/widgets/mcp").
Path string
// OptIn flips the addon to allowlist mode: when true, no route is exposed
// unless it is explicitly opted in with Route.IncludeInMCP. The default (false)
// keeps the expose-everything behavior. ExcludeFromMCP always wins over both.
OptIn bool
// Authenticate optionally gates tools/list and tools/call: the caller must pass
// it, and the context it populates (e.g. an authenticated user) is what each
// route's Authorizer is evaluated against to filter the tool list. When nil,
// the endpoint stays unauthenticated and the list is unfiltered (legacy).
Authenticate HTTPInterceptor
// Guard optionally vets every exposed route when the endpoint is mounted; an
// error stops startup, so a route can't be exposed by accident.
Guard func(method, path string) error
}
MCPConfig configures the optional MCP (Model Context Protocol) addon. It mirrors the OpenAPI addon: enable it via Server.UseMCP and every registered route is exposed as an MCP tool unless opted out with Route.ExcludeFromMCP.
type OpenAPIConfig ¶ added in v0.7.0
type OpenAPISchemaProvider ¶ added in v0.8.3
type OpenAPISchemaProvider interface {
OpenAPISchema() map[string]interface{}
}
OpenAPISchemaProvider lets a type declare its own OpenAPI schema fragment. requiem honors it before falling back to reflection, so types whose JSON shape can't be inferred from their Go declaration (custom MarshalJSON, JSON-encoded string aliases, etc.) can describe themselves accurately.
type RestRouter ¶ added in v0.4.0
RestRouter represents a router for a specific REST API
func (*RestRouter) Delete ¶ added in v0.4.0
func (r *RestRouter) Delete(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor) *Route
Delete handles DELETE HTTP requests for the given path
func (*RestRouter) Get ¶ added in v0.4.0
func (r *RestRouter) Get(path string, handle func(HTTPContext), interceptors ...HTTPInterceptor) *Route
Get handles GET HTTP requests for the given path
func (*RestRouter) Post ¶ added in v0.4.0
func (r *RestRouter) Post(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor) *Route
Post handles POST HTTP requests for the given path
func (*RestRouter) Put ¶ added in v0.4.0
func (r *RestRouter) Put(path string, handle func(HTTPContext), v interface{}, interceptors ...HTTPInterceptor) *Route
Put handles PUT HTTP requests for the given path
type Route ¶ added in v0.7.0
type Route struct {
// contains filtered or unexported fields
}
func (*Route) Authorize ¶ added in v0.9.2
func (rt *Route) Authorize(a Authorizer) *Route
Authorize attaches a per-caller authorization predicate to this route. When MCPConfig.Authenticate is set, tools/list returns a route's tool only if its Authorizer passes for the caller; a route without one is always visible.
func (*Route) Deprecated ¶ added in v0.7.0
func (*Route) Description ¶ added in v0.7.0
func (*Route) ExcludeFromMCP ¶ added in v0.9.0
ExcludeFromMCP hides this route from the MCP tool list. It takes precedence over IncludeInMCP and over MCPConfig.OptIn.
func (*Route) ExcludeFromSpec ¶ added in v0.7.0
func (*Route) IncludeInMCP ¶ added in v0.9.1
IncludeInMCP exposes this route when the addon runs in allowlist mode (MCPConfig.OptIn). It is a no-op in the default expose-everything mode.
func (*Route) MCPTool ¶ added in v0.9.0
MCPTool overrides the auto-generated MCP tool name for this route.
type Router ¶
Router maintains routing paths for a single REST API
func (*Router) NewRestRouter ¶ added in v0.4.0
func (r *Router) NewRestRouter(path string) *RestRouter
NewRestRouter initializes a new REST router on at the given path
type Server ¶
type Server struct {
Port int
BasePath string
ExitOnFatal bool
// contains filtered or unexported fields
}
Server represents a REST API server container Default port is 8080 Default path is /api
func NewServer ¶
func NewServer(controllers ...IHttpController) *Server
NewServer creates a route-based REST API server instance
func (*Server) AutoMigrate ¶ added in v0.5.0
func (s *Server) AutoMigrate(models ...interface{})
func (*Server) GetOpenAPISpec ¶ added in v0.8.2
GetOpenAPISpec returns the OpenAPI 3.0 spec for the server's routes as JSON bytes without starting an HTTP listener. Controllers are loaded into a throwaway router solely to register their routes. Returns nil if UseOpenAPI was never called.
func (*Server) Start ¶
func (s *Server) Start()
Start initializes the API and starts running on the specified port Blocks on current thread
func (*Server) UseHealthcheck ¶ added in v0.6.0
func (s *Server) UseHealthcheck()
func (*Server) UseInMemoryDB ¶ added in v0.5.0
func (*Server) UseMCP ¶ added in v0.9.0
UseMCP enables an optional Model Context Protocol (MCP) endpoint that exposes the server's registered REST routes as MCP tools. It is purely additive: when called, an mcpController is appended to the server's controllers and serves a JSON-RPC 2.0 endpoint (default: the API's namespace + "/mcp"). Once enabled, every route is exposed by default; opt individual routes out with Route.ExcludeFromMCP. The returned handle calls the same tools in-process.
func (*Server) UseOpenAPI ¶ added in v0.7.0
func (s *Server) UseOpenAPI(cfg OpenAPIConfig)
