server

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: BSD-3-Clause-Clear Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConnectRPCRegistration reports a service registration that
	// cannot be mounted, such as one that sets both a connect-go v1 and a v2
	// handler or one whose procedures are already mounted.
	ErrInvalidConnectRPCRegistration = errors.New("invalid connect-rpc registration")
	// ErrMissingInterceptorForm reports an extra interceptor that has no form for
	// the connect-go version of a service being registered.
	ErrMissingInterceptorForm = errors.New("extra connect interceptor has no form for this connect-go version")
)

Functions

func ReadLimitMountOptions added in v0.30.0

func ReadLimitMountOptions(maxBytes int) []connecthttp.Option

ReadLimitMountOptions caps each request message of a connect-go v2 mount at maxBytes, both as read from the wire and after gzip decompression. Non-positive values use the default. Options applied later replace these, so a mount that raises the limit must use ReadLimitMountOptions again with the larger value to keep gzip bounded.

Types

type CORSConfig added in v0.4.1

type CORSConfig struct {
	// Enable CORS for the server (default: true)
	Enabled          bool     `mapstructure:"enabled" json:"enabled" default:"true"`
	AllowedOrigins   []string `mapstructure:"allowedorigins" json:"allowedorigins"`
	AllowedMethods   []string `mapstructure:"allowedmethods" json:"allowedmethods" default:"[\"GET\",\"POST\",\"PATCH\",\"DELETE\",\"OPTIONS\"]"`
	AllowedHeaders   []string `` /* 256-byte string literal not displayed */
	ExposedHeaders   []string `mapstructure:"exposedheaders" json:"exposedheaders"`
	AllowCredentials bool     `mapstructure:"allowcredentials" json:"allowcredentials" default:"true"`
	MaxAge           int      `mapstructure:"maxage" json:"maxage" default:"3600"`
	Debug            bool     `mapstructure:"debug" json:"debug"`

	// Additive fields - appended to base lists at runtime without replacing defaults
	AdditionalMethods        []string `mapstructure:"additionalmethods" json:"additionalmethods"`
	AdditionalHeaders        []string `mapstructure:"additionalheaders" json:"additionalheaders"`
	AdditionalExposedHeaders []string `mapstructure:"additionalexposedheaders" json:"additionalexposedheaders"`
}

CORS Configuration for the server

func (CORSConfig) EffectiveExposedHeaders added in v0.12.0

func (c CORSConfig) EffectiveExposedHeaders() []string

EffectiveExposedHeaders returns ExposedHeaders merged with AdditionalExposedHeaders. Uses case-insensitive deduplication since HTTP headers are case-insensitive per RFC 7230.

func (CORSConfig) EffectiveHeaders added in v0.12.0

func (c CORSConfig) EffectiveHeaders() []string

EffectiveHeaders returns AllowedHeaders merged with AdditionalHeaders. Uses case-insensitive deduplication since HTTP headers are case-insensitive per RFC 7230.

func (CORSConfig) EffectiveMethods added in v0.12.0

func (c CORSConfig) EffectiveMethods() []string

EffectiveMethods returns AllowedMethods merged with AdditionalMethods.

type Config

type Config struct {
	Auth auth.Config `mapstructure:"auth" json:"auth"`

	Cache cache.Config `mapstructure:"cache" json:"cache"`

	GRPC GRPCConfig `mapstructure:"grpc" json:"grpc"`
	// To Deprecate: Use the WithKey[X]Provider StartOptions to register trust providers.
	CryptoProvider          security.Config                          `mapstructure:"cryptoProvider" json:"cryptoProvider"`
	TLS                     TLSConfig                                `mapstructure:"tls" json:"tls"`
	CORS                    CORSConfig                               `mapstructure:"cors" json:"cors"`
	WellKnownConfigRegister func(namespace string, config any) error `mapstructure:"-" json:"-"`

	// Programmatic interceptors injected at startup (not loaded from config)
	ExtraConnectInterceptors []ExtraInterceptor `mapstructure:"-" json:"-"`
	ExtraIPCInterceptors     []ExtraInterceptor `mapstructure:"-" json:"-"`
	// Port to listen on
	Port           int    `mapstructure:"port" json:"port" default:"8080"`
	Host           string `mapstructure:"host,omitempty" json:"host"`
	PublicHostname string `mapstructure:"public_hostname,omitempty" json:"publicHostname"`
	// Http server config
	HTTPServerConfig HTTPServerConfig `mapstructure:"http" json:"http"`
	// Enable pprof
	EnablePprof bool `mapstructure:"enable_pprof" json:"enable_pprof" default:"false"`
	// Trace is for configuring open telemetry based tracing.
	Trace tracing.Config `mapstructure:"trace" json:"trace"`

	// AuthzResolverRegistry contains service-registered resolvers used by the auth interceptor.
	AuthzResolverRegistry *authz.ResolverRegistry `mapstructure:"-" json:"-"`
}

Configurations for the server

func (Config) LogValue added in v0.4.19

func (c Config) LogValue() slog.Value

type ConnectRPC added in v0.4.27

type ConnectRPC struct {
	Mux *http.ServeMux
	// Interceptors are the handler options for services registered with a
	// connect-go v1 handler.
	Interceptors []connect.HandlerOption
	// ServerInterceptors wrap every service registered on a connect-go v2 server.
	ServerInterceptors []connectv2.ServerInterceptor
	// MountOptions apply to every connect-go v2 service; options a service
	// supplies follow them.
	MountOptions      []connecthttp.Option
	ServiceReflection []string
	// contains filtered or unexported fields
}

func (*ConnectRPC) AddExtraInterceptors added in v0.30.0

func (c *ConnectRPC) AddExtraInterceptors(extras ...ExtraInterceptor)

AddExtraInterceptors appends extras after the platform interceptors. When an extra lacks the form for a connect-go version, services on that version can no longer be registered, and services mounted from the interceptor lists directly fail every call, so the interceptor is never silently skipped.

func (*ConnectRPC) RegisterConnectV1 added in v0.30.0

func (c *ConnectRPC) RegisterConnectV1(service string, newHandler func(...connect.HandlerOption) (string, http.Handler)) error

RegisterConnectV1 mounts a connect-go v1 handler built with the server's handler options.

func (*ConnectRPC) RegisterConnectV2 added in v0.30.0

func (c *ConnectRPC) RegisterConnectV2(service string, register func(*connectv2.Server), opts ...connecthttp.Option) (err error)

RegisterConnectV2 registers a service on its own connect-go v2 server with the server interceptors and mounts it with the server's mount options followed by opts.

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type ExtraInterceptor added in v0.30.0

type ExtraInterceptor struct {
	// Name identifies the interceptor in startup errors.
	Name string
	// V1 runs on services registered with a connect-go v1 handler.
	V1 connect.Interceptor
	// V2 runs on services registered with a connect-go v2 server.
	V2 connectv2.ServerInterceptor
}

ExtraInterceptor is a programmatic server interceptor in its connect-go v1 and v2 forms. The platform serves services on both versions, and each service runs only the form for its version, so an interceptor that should cover every service needs both forms.

type GRPCConfig

type GRPCConfig struct {
	// Enable reflection for grpc server (default: true)
	ReflectionEnabled bool `mapstructure:"reflectionEnabled" json:"reflectionEnabled" default:"true"`

	// MaxRecvMsgSizeBytes caps each request message that external clients send to
	// Connect, gRPC, and gRPC-Web handlers, measured after decompression.
	MaxRecvMsgSizeBytes int `mapstructure:"maxRecvMsgSize" json:"maxRecvMsgSize" default:"4194304"` // 4MB = 4 * 1024 * 1024 = 4194304

	// MaxCallRecvMsgSizeBytes and MaxCallSendMsgSizeBytes configure the in-process client used for IPC.
	MaxCallRecvMsgSizeBytes int `mapstructure:"maxCallRecvMsgSize" json:"maxCallRecvMsgSize" default:"4194304"` // 4MB = 4 * 1024 * 1024 = 4194304
	MaxCallSendMsgSizeBytes int `mapstructure:"maxCallSendMsgSize" json:"maxCallSendMsgSize" default:"4194304"` // 4MB = 4 * 1024 * 1024 = 4194304
}

GRPC Server specific configurations

type HTTPServerConfig added in v0.7.2

type HTTPServerConfig struct {
	ReadTimeout       time.Duration `mapstructure:"readTimeout" json:"readTimeout"`
	ReadHeaderTimeout time.Duration `mapstructure:"readHeaderTimeout" json:"readHeaderTimeout"`
	WriteTimeout      time.Duration `mapstructure:"writeTimeout" json:"writeTimeout"`
	IdleTimeout       time.Duration `mapstructure:"idleTimeout" json:"idleTimeout"`
	MaxHeaderBytes    int           `mapstructure:"maxHeaderBytes" json:"maxHeaderBytes"`
	TrustedProxies    []string      `mapstructure:"trustedProxies" json:"trustedProxies"`
}

type OpenTDFServer

type OpenTDFServer struct {
	AuthN               *auth.Authentication
	HTTPMux             *http.ServeMux
	HTTPServer          *http.Server
	ConnectRPCInProcess *inProcessServer
	ConnectRPC          *ConnectRPC
	CacheManager        *cache.Manager

	// To Deprecate: Use the TrustKeyIndex and TrustKeyManager instead
	CryptoProvider *security.StandardCrypto
	Listener       net.Listener

	PublicHostname string
	// contains filtered or unexported fields
}

func NewOpenTDFServer

func NewOpenTDFServer(config Config, logger *logger.Logger, cacheManager *cache.Manager) (*OpenTDFServer, error)

func (OpenTDFServer) Start

func (s OpenTDFServer) Start() error

func (OpenTDFServer) Stop

func (s OpenTDFServer) Stop()

type TLSConfig

type TLSConfig struct {
	// Enable TLS for the server (default: false)
	Enabled bool `mapstructure:"enabled" json:"enabled" default:"false"`
	// Path to the certificate file
	Cert string `mapstructure:"cert" json:"cert"`
	// Path to the key file
	Key string `mapstructure:"key" json:"key"`
}

TLS Configuration for the server

Directories

Path Synopsis
Package memhttp provides an in-memory HTTP server and client.
Package memhttp provides an in-memory HTTP server and client.

Jump to

Keyboard shortcuts

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