Documentation
¶
Overview ¶
Package grpc is GTB's framework-integration layer over the extracted gRPC transport module.
The hardened gRPC server now lives in gitlab.com/phpboyscout/go/transport/grpc; this package binds it to the GTB config container. It provides the config-driven adapters — ServerSettingsFromConfig, ObserveServerSettingsFromConfig, NewServerFromReader, StartFromReader, DialLocalFromReader, RegisterFromReader, plus RateLimitConfigFromConfig / CircuitBreakerConfigFromConfig — which read a service's config and call the transport constructors. The GTB config-selection options WithConfigPrefix and WithPort steer that resolution. The config adapters name the go/transit gRPC middleware types (RateLimitConfig, CircuitBreakerConfig) directly.
The gRPC interceptors are no longer re-exported here: code that wants the pure server API imports gitlab.com/phpboyscout/go/transport/grpc or the interceptors from gitlab.com/phpboyscout/go/transit/grpc directly.
Index ¶
- Constants
- func CircuitBreakerConfigFromConfig(cfg config.Reader, prefix string) transitgrpc.CircuitBreakerConfig
- func DialLocalFromReader(cfg config.Reader, opts ...any) (*grpc.ClientConn, error)
- func NewServerFromReader(cfg config.Reader, opts ...any) (*grpc.Server, error)
- func ObserveServerSettingsFromConfig(cfg config.Binder, prefix string, ...) (*config.ObservedSection[transportgrpc.ServerSettings], error)
- func RateLimitConfigFromConfig(cfg config.Reader, prefix string) transitgrpc.RateLimitConfig
- func RegisterFromReader(_ context.Context, id string, controller controls.Controllable, ...) (*grpc.Server, error)
- func ServerSettingsFromConfig(cfg config.Reader, prefix string) transportgrpc.ServerSettings
- func StartFromReader(cfg config.Reader, log logger.Logger, srv *grpc.Server, opts ...any) controls.StartFunc
- type ServerOption
Constants ¶
ConfigKeySharedPort is the shared fallback port used when the per-server port key (<prefix>.port) is unset.
const DefaultConfigPrefix = "server.grpc"
DefaultConfigPrefix is the config block a gRPC server reads its port, reflection and TLS settings from unless overridden with WithConfigPrefix.
Variables ¶
This section is empty.
Functions ¶
func CircuitBreakerConfigFromConfig ¶ added in v0.23.0
func CircuitBreakerConfigFromConfig(cfg config.Reader, prefix string) transitgrpc.CircuitBreakerConfig
CircuitBreakerConfigFromConfig builds a transitgrpc.CircuitBreakerConfig from the config layer under "<prefix>.circuitbreaker.*" (prefix defaults to "server.grpc").
Unset keys keep their transitgrpc.DefaultCircuitBreakerConfig values. The code-only fields (IsFailure, OnStateChange) are never read from config.
func DialLocalFromReader ¶ added in v0.32.0
DialLocalFromReader dials the gRPC server described by cfg over the loopback interface, using transport security that matches the server's own TLS config (server.grpc.tls -> server.tls). Intended for in-process callers such as the grpc-gateway. The opts variadic accepts GTB ServerOption values (WithConfigPrefix to dial a non-default server) and grpc.DialOption values.
func NewServerFromReader ¶ added in v0.32.0
NewServerFromReader returns a new preconfigured grpc.Server from config. GTB config-selection options (WithConfigPrefix) select the block the reflection flag is read from; grpc.ServerOption values are forwarded.
func ObserveServerSettingsFromConfig ¶ added in v0.30.0
func ObserveServerSettingsFromConfig( cfg config.Binder, prefix string, opts ...config.SectionBindingOption[transportgrpc.ServerSettings], ) (*config.ObservedSection[transportgrpc.ServerSettings], error)
ObserveServerSettingsFromConfig binds gRPC server settings to cfg and keeps a typed snapshot rehydrated after successful config reloads.
func RateLimitConfigFromConfig ¶ added in v0.23.0
func RateLimitConfigFromConfig(cfg config.Reader, prefix string) transitgrpc.RateLimitConfig
RateLimitConfigFromConfig builds a transitgrpc.RateLimitConfig from the config layer under "<prefix>.ratelimit.*" (prefix defaults to "server.grpc").
Unset keys keep their transitgrpc.DefaultRateLimitConfig values. The code-only fields (KeyFunc, OnLimited) are never read from config; wiring stays explicit.
func RegisterFromReader ¶ added in v0.32.0
func RegisterFromReader(_ context.Context, id string, controller controls.Controllable, cfg config.Reader, log logger.Logger, opts ...any) (*grpc.Server, error)
RegisterFromReader creates a new gRPC server from config and registers it with the controller under the given id. The opts variadic accepts GTB ServerOption values (WithConfigPrefix, WithPort), transport RegisterOption values (interceptors) and grpc.ServerOption values.
func ServerSettingsFromConfig ¶ added in v0.30.0
func ServerSettingsFromConfig(cfg config.Reader, prefix string) transportgrpc.ServerSettings
ServerSettingsFromConfig resolves gRPC server settings from GTB config. It preserves the existing fallback from <prefix>.port to server.port.
func StartFromReader ¶ added in v0.32.0
func StartFromReader(cfg config.Reader, log logger.Logger, srv *grpc.Server, opts ...any) controls.StartFunc
StartFromReader returns a curried function suitable for use with the controls package. With no options it reads its port and TLS from the default "server.grpc" config block; pass WithConfigPrefix/WithPort to target a custom server. TLS cascades: <prefix>.tls.* overrides server.tls.* shared defaults.
Types ¶
type ServerOption ¶ added in v0.9.0
type ServerOption func(*serverConfig)
ServerOption selects which GTB config block (and, optionally, an explicit port) the *FromReader adapters read. It is distinct from the transport's own gitlab.com/phpboyscout/go/transport/grpc.ServerOption; the adapters accept GTB options (config selection) and forward grpc.ServerOption / grpc.DialOption / transport RegisterOption values to the underlying constructor.
func WithConfigPrefix ¶ added in v0.9.0
func WithConfigPrefix(prefix string) ServerOption
WithConfigPrefix sets the config block the server reads from (default "server.grpc"). Use it to run a second gRPC server on its own block, e.g. "server.internal".
func WithPort ¶ added in v0.9.0
func WithPort(port int) ServerOption
WithPort sets the listen (or dial) port explicitly, bypassing config lookup.