server

package
v4.1.14 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
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

type OpenAPISpecWriter interface {
	WriteOpenAPISpec(w io.Writer) error
}

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 WithDebugMode

func WithDebugMode(enabled bool) Option

WithDebugMode runs the gin server in debug mode (e.g. not setting the release mode)

func WithMetrics

func WithMetrics(enabled bool, requestDurationBuckets ...float64) Option

WithMetrics enables prometheus metrics endpoints. The request duration can be provided if they should differ from the default duration buckets

func WithNoRecursionDetection

func WithNoRecursionDetection() Option

WithNoRecursionDetection disables the query recursion detection

func WithProfiling

func WithProfiling(enabled bool) Option

WithProfiling enables runtime profiling endpoints

func WithQueryRateLimit

func WithQueryRateLimit(r rate.Limit, b, maxConcurrent int) Option

WithQueryRateLimit enables a global rate limit for query calls

func WithTracing

func WithTracing(enabled bool) Option

WithTracing enables trace propagation

Jump to

Keyboard shortcuts

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