Documentation ¶
Index ¶
- Variables
- func ValidateChannelOptions(c ChannelOptions) error
- func ValidateNamespace(ns ChannelNamespace) error
- func ValidateRpcNamespace(ns RpcNamespace) error
- func ValidateRpcOptions(_ RpcOptions) error
- type ChannelNamespace
- type ChannelOptions
- type Config
- type Container
- func (n *Container) ChannelOptions(ch string) (string, ChannelOptions, bool, error)
- func (n *Container) Config() Config
- func (n *Container) IsPrivateChannel(ch string) bool
- func (n *Container) IsUserLimited(ch string) bool
- func (n *Container) NumNamespaces() int
- func (n *Container) NumRpcNamespaces() int
- func (n *Container) PersonalChannel(user string) string
- func (n *Container) Reload(c Config) error
- func (n *Container) RpcOptions(method string) (RpcOptions, bool, error)
- func (n *Container) UserAllowed(ch string, user string) bool
- type RpcNamespace
- type RpcOptions
Constants ¶
This section is empty.
Variables ¶
var DefaultConfig = Config{
ChannelPrivatePrefix: "$",
ChannelNamespaceBoundary: ":",
ChannelUserBoundary: "#",
ChannelUserSeparator: ",",
RpcNamespaceBoundary: ":",
}
DefaultConfig has default config options.
Functions ¶
func ValidateChannelOptions ¶
func ValidateChannelOptions(c ChannelOptions) error
func ValidateNamespace ¶
func ValidateNamespace(ns ChannelNamespace) error
func ValidateRpcNamespace ¶ added in v3.1.0
func ValidateRpcNamespace(ns RpcNamespace) error
func ValidateRpcOptions ¶ added in v3.1.0
func ValidateRpcOptions(_ RpcOptions) error
Types ¶
type ChannelNamespace ¶
type ChannelNamespace struct { // Name is a unique namespace name. Name string `mapstructure:"name" json:"name"` // Options for namespace determine channel options for channels // belonging to this namespace. ChannelOptions `mapstructure:",squash"` }
ChannelNamespace allows to create channels with different channel options.
type ChannelOptions ¶
type ChannelOptions struct { // Presence turns on presence information for channel. Presence has // information about all clients currently subscribed to a channel. Presence bool `mapstructure:"presence" json:"presence"` // JoinLeave turns on join/leave messages for a channel. // When client subscribes on a channel join message sent to all // subscribers in this channel (including current client). When client // leaves channel (unsubscribes) leave message sent. This option does // not fit well for channels with many subscribers because every // subscribe/unsubscribe event results into join/leave event broadcast // to all other active subscribers thus overloads server with tons of // messages. Use accurately for channels with small number of active // subscribers. JoinLeave bool `mapstructure:"join_leave" json:"join_leave"` // HistorySize determines max amount of history messages for a channel, // Zero value means no history for channel. Centrifuge history has an // auxiliary role with current Engines – it can not replace your backend // persistent storage. HistorySize int `mapstructure:"history_size" json:"history_size"` // HistoryTTL is a time to live for history cache. Server maintains a window of // messages in memory (or in Redis with Redis engine), to prevent infinite memory // grows it's important to remove history for inactive channels. HistoryTTL tools.Duration `mapstructure:"history_ttl" json:"history_ttl"` // Recover enables recovery mechanism for channels. This means that // server will try to recover missed messages for resubscribing client. // This option uses publications from history and must be used with reasonable // HistorySize and HistoryTTL configuration. Recover bool `mapstructure:"recover" json:"recover"` // Position enables client positioning. Position bool `mapstructure:"position" json:"position"` // Protected when on will prevent a client to subscribe to arbitrary channels in a // namespace. In this case Centrifugo will only allow client to subscribe on user-limited // channels, on channels returned by proxy response or channels listed inside JWT. // Client-side subscriptions to arbitrary channels will be rejected with PermissionDenied // error. Server-side channels belonging to protected namespace passed by client itself during // connect will be ignored. Protected bool `mapstructure:"protected" json:"protected"` // Publish enables possibility for clients to publish messages into channels. // Once enabled client can publish into channel and that publication will be // sent to all current channel subscribers. Publish bool `mapstructure:"publish" json:"publish"` // SubscribeToPublish turns on an automatic check that client subscribed // on a channel before allow publishing. SubscribeToPublish bool `mapstructure:"subscribe_to_publish" json:"subscribe_to_publish"` // Anonymous enables anonymous access (with empty user ID) to channel. // In most situations your application works with authenticated users so // every user has its own unique user ID. But if you provide real-time // features for public access you may need unauthenticated access to channels. // Turn on this option and use empty string as user ID. Anonymous bool `mapstructure:"anonymous" json:"anonymous"` // PresenceDisableForClient prevents presence to be asked by clients. // In this case it's available only over server-side presence call. PresenceDisableForClient bool `mapstructure:"presence_disable_for_client" json:"presence_disable_for_client"` // HistoryDisableForClient prevents history to be asked by clients. // In this case it's available only over server-side history call. // History recover mechanism if enabled will continue to work for // clients anyway. HistoryDisableForClient bool `mapstructure:"history_disable_for_client" json:"history_disable_for_client"` // ProxySubscribe turns on proxying subscribe decision for channels. ProxySubscribe bool `mapstructure:"proxy_subscribe" json:"proxy_subscribe"` // ProxyPublish turns on proxying publish decision for channels. ProxyPublish bool `mapstructure:"proxy_publish" json:"proxy_publish"` // SubscribeProxyName of proxy to use for subscribe operations in namespace. SubscribeProxyName string `mapstructure:"subscribe_proxy_name" json:"subscribe_proxy_name"` // PublishProxyName of proxy to use for publish operations in namespace. PublishProxyName string `mapstructure:"publish_proxy_name" json:"publish_proxy_name"` }
ChannelOptions represent channel specific configuration for namespace or global channel options if set on top level of configuration.
type Config ¶
type Config struct { // ChannelOptions embedded on top level. ChannelOptions // Namespaces – list of namespaces for custom channel options. Namespaces []ChannelNamespace // RpcOptions embedded on top level. RpcOptions // RpcNamespaces - list of rpc namespace for custom rpc options. RpcNamespaces []RpcNamespace // RpcNamespaceBoundary is a string separator which must be put after // rpc namespace part in rpc method. RpcNamespaceBoundary string // ChannelUserBoundary is a string separator which must be set before // allowed users part in channel name. // ChannelPrivatePrefix is a prefix in channel name which indicates that // channel is private. ChannelPrivatePrefix string // ChannelNamespaceBoundary is a string separator which must be put after // namespace part in channel name. ChannelNamespaceBoundary string // ChannelUserBoundary is a string separator which must be set before // allowed users part in channel name. ChannelUserBoundary string // ChannelUserSeparator separates allowed users in user part of channel name. // So you can limit access to channel to limited set of users. ChannelUserSeparator string // UserSubscribeToPersonal enables automatic subscribing to personal channel // by user. Only users with user ID defined will subscribe to personal // channels, anonymous users are ignored. UserSubscribeToPersonal bool // UserPersonalChannelPrefix defines prefix to be added to user personal channel. // This should match one of configured namespace names. By default no namespace // used for personal channel. UserPersonalChannelNamespace string // UserPersonalSingleConnection turns on a mode in which Centrifugo will try to // maintain only a single connection for each user in the same moment. As soon as // user establishes a connection other connections from the same user will be closed // with connection limit reason. // This feature works with a help of presence information inside personal channel. // So presence should be turned on in personal channel. UserPersonalSingleConnection bool // ClientInsecure turns on insecure mode for client connections - when it's // turned on then no authentication required at all when connecting to Centrifugo, // anonymous access and publish allowed for all channels, no connection expire // performed. This can be suitable for demonstration or personal usage. ClientInsecure bool // ClientAnonymous when set to true, allows connect requests without specifying // a token or setting Credentials in authentication middleware. The resulting // user will have empty string for user ID, meaning user can only subscribe // to anonymous channels. ClientAnonymous bool // ClientConcurrency when set allows processing client commands concurrently // with provided concurrency level. By default commands processed sequentially // one after another. ClientConcurrency int }
Config ...
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
Container ...
func (*Container) ChannelOptions ¶
ChannelOptions returns channel options for channel using current channel config.
func (*Container) IsPrivateChannel ¶
IsPrivateChannel checks if channel requires token to subscribe. In case of token-protected channel subscription request must contain a proper token.
func (*Container) IsUserLimited ¶
IsUserLimited returns whether channel is user-limited.
func (*Container) NumNamespaces ¶ added in v3.2.1
NumNamespaces returns number of configured namespaces.
func (*Container) NumRpcNamespaces ¶ added in v3.2.1
NumRpcNamespaces returns number of configured rpc namespaces.
func (*Container) PersonalChannel ¶
PersonalChannel returns personal channel for user based on node configuration.
func (*Container) RpcOptions ¶ added in v3.1.0
func (n *Container) RpcOptions(method string) (RpcOptions, bool, error)
RpcOptions returns rpc options for method using current config.
type RpcNamespace ¶ added in v3.1.0
type RpcNamespace struct { // Name is a unique rpc namespace name. Name string `mapstructure:"name" json:"name"` // Options for rpc namespace. RpcOptions `mapstructure:",squash"` }
RpcNamespace allows to create rules for different rpc.
type RpcOptions ¶ added in v3.1.0
type RpcOptions struct { // RpcProxyName which should be used for RPC namespace. RpcProxyName string `mapstructure:"rpc_proxy_name" json:"rpc_proxy_name,omitempty"` }
RpcOptions ...