Documentation
¶
Index ¶
- Constants
- func GenerateSpec(ctx context.Context, path string, ow OpenAPISpecWriter) error
- type DefaultServer
- type OpenAPISpecWriter
- type Option
- func WithCORSOrigins(origins ...string) Option
- func WithDebugMode(enabled bool) Option
- func WithMetrics(enabled bool, requestDurationBuckets ...float64) Option
- func WithMetricsRegistry(reg *prometheus.Registry) Option
- func WithNoRecursionDetection() Option
- func WithProfiling(enabled bool) Option
- func WithQueryRateLimit(r rate.Limit, b, maxConcurrent int) Option
- func WithTracing(enabled bool) Option
Constants ¶
const (
// RuntimeIDHeaderKey denotes the header name / key that identifies the server runtime ID
RuntimeIDHeaderKey = "X-GOPROBE-RUNTIME-ID"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateSpec ¶
func GenerateSpec(ctx context.Context, path string, ow OpenAPISpecWriter) error
GenerateSpec writes the OpenAPI spec to a file
Types ¶
type DefaultServer ¶
type DefaultServer struct {
// contains filtered or unexported fields
}
DefaultServer is the default API server, allowing middlewares and settings to be re-used across binaries serving an API
func NewDefault ¶
func NewDefault(serviceName, addr string, opts ...Option) *DefaultServer
NewDefault creates a new API server
func (*DefaultServer) API ¶
func (server *DefaultServer) API() huma.API
API returns the huma API server which is used to register and document endpoints
func (*DefaultServer) QueryRateLimiter ¶
func (server *DefaultServer) QueryRateLimiter() (int, *rate.Limiter, bool)
QueryRateLimiter returns the maximum number of concurrent queries and the global rate limiter, if enabled (if not it return nil and false)
func (*DefaultServer) Serve ¶
func (server *DefaultServer) Serve() error
Serve starts the API server after adding additional (optional) routes
func (*DefaultServer) Shutdown ¶
func (server *DefaultServer) Shutdown(ctx context.Context) error
Shutdown shuts down the API server
func (*DefaultServer) WriteOpenAPISpec ¶
func (server *DefaultServer) WriteOpenAPISpec(w io.Writer) error
WriteOpenAPISpec writes the full OpenAPI spec to the writer w. It implements the OpenAPISpecWriter interface
type OpenAPISpecWriter ¶
OpenAPISpecWriter can be implemented by any server able to produce an OpenAPI spec from its registered routes
type Option ¶
type Option func(*DefaultServer)
Option denotes a functional option fo a default server instance
func WithCORSOrigins ¶ added in v4.2.7
WithCORSOrigins sets the allowed CORS origins. When no origins are supplied (the default), no CORS headers are sent and browsers will block cross-origin requests. Provide explicit frontend origin(s) for deployments that expose the API directly to browsers, e.g. "https://query.example.com".
func WithDebugMode ¶
WithDebugMode runs the gin server in debug mode (e.g. not setting the release mode)
func WithMetrics ¶
WithMetrics enables prometheus metrics endpoints. The request duration can be provided if they should differ from the default duration buckets
func WithMetricsRegistry ¶ added in v4.2.7
func WithMetricsRegistry(reg *prometheus.Registry) Option
WithMetricsRegistry sets a custom prometheus registry for the metrics endpoint. If not set, the telemetry/metrics middleware creates its own isolated registry.
func WithNoRecursionDetection ¶
func WithNoRecursionDetection() Option
WithNoRecursionDetection disables the query recursion detection
func WithProfiling ¶
WithProfiling enables runtime profiling endpoints
func WithQueryRateLimit ¶
WithQueryRateLimit enables a global rate limit for query calls