config

package
v6.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package config contains Centrifugo Config and the code to load it.

Index

Constants

View Source
const (
	DefaultProxyName   = "default"
	TransportErrorMode = "transport"
)

Variables

This section is empty.

Functions

func DefineFlags

func DefineFlags(rootCmd *cobra.Command)

func GetConfig

func GetConfig(cmd *cobra.Command, configFile string) (Config, Meta, error)

Types

type Config

type Config struct {
	// HTTP is a configuration for Centrifugo HTTP server.
	HTTP configtypes.HTTPServer `mapstructure:"http_server" json:"http_server" envconfig:"http_server" toml:"http_server" yaml:"http_server"`
	// Log is a configuration for logging.
	Log configtypes.Log `mapstructure:"log" json:"log" envconfig:"log" toml:"log" yaml:"log"`
	// Engine is a configuration for Centrifugo engine. It's a handy combination of Broker and PresenceManager.
	// Currently only memory and redis engines are supported – both implement all the features. For more granular
	// control use Broker and PresenceManager options.
	Engine configtypes.Engine `mapstructure:"engine" json:"engine" envconfig:"engine" toml:"engine" yaml:"engine"`
	// Broker allows to configure a message broker to use. Broker is responsible for PUB/SUB functionality
	// and channel message history and idempotency cache .
	// By default, memory Broker is used. Memory broker is superfast, but it's not distributed and all
	// data stored in memory (thus lost after node restart). Redis Broker provides seamless horizontal
	// scalability, fault-tolerance, and persistence over Centrifugo restarts. Centrifugo also supports
	// Nats Broker which only implements at most once PUB/SUB semantics.
	Broker configtypes.Broker `mapstructure:"broker" json:"broker" envconfig:"broker" toml:"broker" yaml:"broker"`
	// PresenceManager allows to configure a presence manager to use. Presence manager is responsible for
	// presence information storage and retrieval. By default, memory PresenceManager is used. Memory
	// PresenceManager is superfast, but it's not distributed. Redis PresenceManager provides a seamless
	// horizontal scalability.
	PresenceManager configtypes.PresenceManager `` /* 132-byte string literal not displayed */

	// Client contains real-time client connection related configuration.
	Client configtypes.Client `mapstructure:"client" json:"client" envconfig:"client" toml:"client" yaml:"client"`
	// Channel contains real-time channel related configuration.
	Channel configtypes.Channel `mapstructure:"channel" json:"channel" envconfig:"channel" toml:"channel" yaml:"channel"`
	// RPC is a configuration for client RPC calls.
	RPC configtypes.RPC `mapstructure:"rpc" json:"rpc" envconfig:"rpc" toml:"rpc" yaml:"rpc"`
	// Proxies is an array of proxies with custom names for the more granular control of channel-related events
	// in different channel namespaces.
	Proxies configtypes.NamedProxies `mapstructure:"proxies" default:"[]" json:"proxies" envconfig:"proxies" yaml:"proxies" toml:"proxies"`

	// HttpAPI is a configuration for HTTP server API. It's enabled by default.
	HttpAPI configtypes.HttpAPI `mapstructure:"http_api" json:"http_api" envconfig:"http_api" toml:"http_api" yaml:"http_api"`
	// GrpcAPI is a configuration for gRPC server API. It's disabled by default.
	GrpcAPI configtypes.GrpcAPI `mapstructure:"grpc_api" json:"grpc_api" envconfig:"grpc_api" toml:"grpc_api" yaml:"grpc_api"`

	// Consumers is a configuration for message queue consumers. For example, Centrifugo can consume
	// messages from PostgreSQL transactional outbox table, or from Kafka topics.
	Consumers configtypes.Consumers `mapstructure:"consumers" default:"[]" json:"consumers" envconfig:"consumers" toml:"consumers" yaml:"consumers"`

	// WebSocket configuration. This transport is enabled by default.
	WebSocket configtypes.WebSocket `mapstructure:"websocket" json:"websocket" envconfig:"websocket" toml:"websocket" yaml:"websocket"`
	// SSE is a configuration for Server-Sent Events based bidirectional emulation transport.
	SSE configtypes.SSE `mapstructure:"sse" json:"sse" envconfig:"sse" toml:"sse" yaml:"sse"`
	// HTTPStream is a configuration for HTTP streaming based bidirectional emulation transport.
	HTTPStream configtypes.HTTPStream `mapstructure:"http_stream" json:"http_stream" envconfig:"http_stream" toml:"http_stream" yaml:"http_stream"`
	// WebTransport is a configuration for WebTransport transport. EXPERIMENTAL.
	WebTransport configtypes.WebTransport `mapstructure:"webtransport" json:"webtransport" envconfig:"webtransport" toml:"webtransport" yaml:"webtransport"`
	// UniSSE is a configuration for unidirectional Server-Sent Events transport.
	UniSSE configtypes.UniSSE `mapstructure:"uni_sse" json:"uni_sse" envconfig:"uni_sse" toml:"uni_sse" yaml:"uni_sse"`
	// UniHTTPStream is a configuration for unidirectional HTTP streaming transport.
	UniHTTPStream configtypes.UniHTTPStream `` /* 127-byte string literal not displayed */
	// UniWS is a configuration for unidirectional WebSocket transport.
	UniWS configtypes.UniWebSocket `mapstructure:"uni_websocket" json:"uni_websocket" envconfig:"uni_websocket" toml:"uni_websocket" yaml:"uni_websocket"`
	// UniGRPC is a configuration for unidirectional gRPC transport.
	UniGRPC configtypes.UniGRPC `mapstructure:"uni_grpc" json:"uni_grpc" envconfig:"uni_grpc" toml:"uni_grpc" yaml:"uni_grpc"`
	// Emulation endpoint is enabled automatically when at least one bidirectional emulation transport
	// is configured (SSE or HTTP Stream).
	Emulation configtypes.Emulation `mapstructure:"emulation" json:"emulation" envconfig:"emulation" toml:"emulation" yaml:"emulation"`
	// Admin web UI configuration.
	Admin configtypes.Admin `mapstructure:"admin" json:"admin" envconfig:"admin" toml:"admin" yaml:"admin"`
	// Prometheus metrics configuration.
	Prometheus configtypes.Prometheus `mapstructure:"prometheus" json:"prometheus" envconfig:"prometheus" toml:"prometheus" yaml:"prometheus"`
	// Health check endpoint configuration.
	Health configtypes.Health `mapstructure:"health" json:"health" envconfig:"health" toml:"health" yaml:"health"`
	// Swagger documentation (for server HTTP API) configuration.
	Swagger configtypes.Swagger `mapstructure:"swagger" json:"swagger" envconfig:"swagger" toml:"swagger" yaml:"swagger"`
	// Debug helps to enable Go profiling endpoints.
	Debug configtypes.Debug `mapstructure:"debug" json:"debug" envconfig:"debug" toml:"debug" yaml:"debug"`

	// OpenTelemetry is a configuration for OpenTelemetry tracing.
	OpenTelemetry configtypes.OpenTelemetry `mapstructure:"opentelemetry" json:"opentelemetry" envconfig:"opentelemetry" toml:"opentelemetry" yaml:"opentelemetry"`
	// Graphite is a configuration for export metrics to Graphite.
	Graphite configtypes.Graphite `mapstructure:"graphite" json:"graphite" envconfig:"graphite" toml:"graphite" yaml:"graphite"`
	// UsageStats is a configuration for usage stats sending.
	UsageStats configtypes.UsageStats `mapstructure:"usage_stats" json:"usage_stats" envconfig:"usage_stats" toml:"usage_stats" yaml:"usage_stats"`
	// Node is a configuration for Centrifugo Node as part of cluster.
	Node configtypes.Node `mapstructure:"node" json:"node" envconfig:"node" toml:"node" yaml:"node"`
	// Shutdown is a configuration for graceful shutdown.
	Shutdown configtypes.Shutdown `mapstructure:"shutdown" json:"shutdown" envconfig:"shutdown" toml:"shutdown" yaml:"shutdown"`

	// PidFile is a path to write a file with Centrifugo process PID.
	PidFile string `mapstructure:"pid_file" json:"pid_file" envconfig:"pid_file" toml:"pid_file" yaml:"pid_file"`
	// EnableUnreleasedFeatures enables unreleased features. These features are not stable and may be removed even
	// in minor release update. Evaluate and share feedback if you find some feature useful and want it to be stabilized.
	EnableUnreleasedFeatures bool `` /* 182-byte string literal not displayed */
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig is a helper to be used in tests.

func (Config) Validate

func (c Config) Validate() error

Validate validates config and returns error if problems found.

type Container

type Container struct {
	ChannelOptionsCacheTTL time.Duration
	// contains filtered or unexported fields
}

Container wraps configuration providing sync access, reload and compilation of required parts.

func NewContainer

func NewContainer(config Config) (*Container, error)

NewContainer creates new Container.

func (*Container) ChannelOptions

func (n *Container) ChannelOptions(ch string) (string, string, configtypes.ChannelOptions, bool, error)

ChannelOptions returns channel options for channel using current channel config.

func (*Container) Config

func (n *Container) Config() Config

Config returns a copy of node Config.

func (*Container) IsPrivateChannel

func (n *Container) IsPrivateChannel(ch string) bool

IsPrivateChannel checks if channel requires token to subscribe. In case of token-protected channel subscription request must contain a proper token.

func (*Container) IsUserLimited

func (n *Container) IsUserLimited(ch string) bool

IsUserLimited returns whether channel is user-limited.

func (*Container) NumNamespaces

func (n *Container) NumNamespaces() int

NumNamespaces returns number of configured namespaces.

func (*Container) NumRpcNamespaces

func (n *Container) NumRpcNamespaces() int

NumRpcNamespaces returns number of configured rpc namespaces.

func (*Container) PersonalChannel

func (n *Container) PersonalChannel(user string) string

PersonalChannel returns personal channel for user based on node configuration.

func (*Container) Reload

func (n *Container) Reload(c Config) error

Reload node config.

func (*Container) RpcOptions

func (n *Container) RpcOptions(method string) (configtypes.RpcOptions, bool, error)

RpcOptions returns rpc options for method using current config.

func (*Container) UserAllowed

func (n *Container) UserAllowed(ch string, user string) bool

UserAllowed checks if user can subscribe on channel - as channel can contain special part in the end to indicate which users allowed to subscribe on it.

type Meta

type Meta struct {
	FileNotFound bool
	UnknownKeys  []string
	UnknownEnvs  []string
	KnownEnvVars map[string]envconfig.VarInfo
}

Directories

Path Synopsis
Package envconfig implements decoding of environment variables based on a user defined specification.
Package envconfig implements decoding of environment variables based on a user defined specification.

Jump to

Keyboard shortcuts

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