Documentation ¶
Overview ¶
Package gocent is a Go language client for Centrifugo real-time messaging server HTTP API.
Index ¶
- Variables
- type ChannelsResult
- type Client
- func (c *Client) Broadcast(ctx context.Context, channels []string, data []byte) error
- func (c *Client) Channels(ctx context.Context) (ChannelsResult, error)
- func (c *Client) Disconnect(ctx context.Context, user string) error
- func (c *Client) History(ctx context.Context, channel string) (HistoryResult, error)
- func (c *Client) HistoryRemove(ctx context.Context, channel string) error
- func (c *Client) Info(ctx context.Context) (InfoResult, error)
- func (c *Client) Pipe() *Pipe
- func (c *Client) Presence(ctx context.Context, channel string) (PresenceResult, error)
- func (c *Client) PresenceStats(ctx context.Context, channel string) (PresenceStatsResult, error)
- func (c *Client) Publish(ctx context.Context, channel string, data []byte) error
- func (c *Client) SendPipe(ctx context.Context, pipe *Pipe) ([]Reply, error)
- func (c *Client) SetHTTPClient(httpClient *http.Client)
- func (c *Client) Unsubscribe(ctx context.Context, channel, user string) error
- type ClientInfo
- type Command
- type Config
- type ErrStatusCode
- type Error
- type HistoryResult
- type InfoResult
- type NodeInfo
- type Pipe
- func (p *Pipe) AddBroadcast(channels []string, data []byte) error
- func (p *Pipe) AddChannels() error
- func (p *Pipe) AddDisconnect(user string) error
- func (p *Pipe) AddHistory(channel string) error
- func (p *Pipe) AddHistoryRemove(channel string) error
- func (p *Pipe) AddInfo() error
- func (p *Pipe) AddPresence(channel string) error
- func (p *Pipe) AddPresenceStats(channel string) error
- func (p *Pipe) AddPublish(channel string, data []byte) error
- func (p *Pipe) AddUnsubscribe(channel string, user string) error
- func (p *Pipe) Reset()
- type PresenceResult
- type PresenceStatsResult
- type Publication
- type Reply
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMalformedResponse can be returned when server replied with invalid response. ErrMalformedResponse = errors.New("malformed response returned from server") // ErrPipeEmpty returned when no commands found in Pipe. ErrPipeEmpty = errors.New("no commands in pipe") )
var DefaultHTTPClient = &http.Client{Transport: &http.Transport{ MaxIdleConnsPerHost: 100, }, Timeout: time.Second}
DefaultHTTPClient will be used by default for HTTP requests.
Functions ¶
This section is empty.
Types ¶
type ChannelsResult ¶
type ChannelsResult struct {
Channels []string `json:"channels"`
}
ChannelsResult is a result of channels command.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is API client for project registered in server.
func (*Client) Channels ¶
func (c *Client) Channels(ctx context.Context) (ChannelsResult, error)
Channels returns information about active channels (with one or more subscribers) on server.
func (*Client) Disconnect ¶
Disconnect allows to close all connections of user to server.
func (*Client) HistoryRemove ¶ added in v2.1.0
HistoryRemove removes channel history.
func (*Client) Info ¶
func (c *Client) Info(ctx context.Context) (InfoResult, error)
Info returnes information about server nodes.
func (*Client) PresenceStats ¶
PresenceStats returns short channel presence information (only counters).
func (*Client) SendPipe ¶
SendPipe sends Commands collected in Pipe to Centrifugo. Using this method you should manually inspect all replies.
func (*Client) SetHTTPClient ¶
SetHTTPClient allows to set custom http Client to use for requests. Not goroutine-safe.
type ClientInfo ¶
type ClientInfo struct { User string `json:"user"` Client string `json:"client"` ConnInfo json.RawMessage `json:"conn_info,omitempty"` ChanInfo json.RawMessage `json:"chan_info,omitempty"` }
ClientInfo represents information about one client connection to Centrifugo. This struct used in messages published by clients, join/leave events, presence data.
type Config ¶
type Config struct { // Addr is Centrifugo API endpoint. Addr string // GetAddr when set will be used before every API call to extract // Centrifugo API endpoint. In this case Addr field of Config will be // ignored. Nil value means using static Config.Addr field. GetAddr func() (string, error) // Key is Centrifugo API key. Key string // HTTPClient is a custom HTTP client to be used. // If nil DefaultHTTPClient will be used. HTTPClient *http.Client }
Config of client.
type ErrStatusCode ¶
type ErrStatusCode struct {
Code int
}
ErrStatusCode can be returned in case request to server resulted in wrong status code.
func (ErrStatusCode) Error ¶
func (e ErrStatusCode) Error() string
type HistoryResult ¶
type HistoryResult struct {
Publications []Publication `json:"publications"`
}
HistoryResult is a result of history command.
type InfoResult ¶
type InfoResult struct {
Nodes []NodeInfo `json:"nodes"`
}
InfoResult is a result of info command.
type NodeInfo ¶
type NodeInfo struct { // UID is a unique id of running node. UID string `json:"uid"` // Name is a name of node (config defined or generated automatically). Name string `json:"name"` // Version of Centrifugo node. Version string `json:"version"` // NumClients is a number of clients connected to node. NumClients int `json:"num_clients"` // NumUsers is a number of unique users connected to node. NumUsers int `json:"num_users"` // NumChannels is a number of channels on node. NumChannels int `json:"num_channels"` // Uptime of node in seconds. Uptime int `json:"uptime"` }
NodeInfo contains information and statistics about Centrifugo node.
type Pipe ¶
type Pipe struct {
// contains filtered or unexported fields
}
Pipe allows to send several commands in one HTTP request.
func (*Pipe) AddBroadcast ¶
AddBroadcast adds broadcast command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddChannels ¶
AddChannels adds channels command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddDisconnect ¶
AddDisconnect adds disconnect command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddHistory ¶
AddHistory adds history command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddHistoryRemove ¶ added in v2.1.0
AddHistoryRemove adds history remove command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddInfo ¶
AddInfo adds info command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddPresence ¶
AddPresence adds presence command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddPresenceStats ¶
AddPresenceStats adds presence stats command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddPublish ¶
AddPublish adds publish command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
func (*Pipe) AddUnsubscribe ¶
AddUnsubscribe adds unsubscribe command to client command buffer but not actually sends request to server until Pipe will be explicitly sent.
type PresenceResult ¶
type PresenceResult struct {
Presence map[string]ClientInfo `json:"presence"`
}
PresenceResult is a result of presence command.
type PresenceStatsResult ¶
type PresenceStatsResult struct { NumUsers int32 `json:"num_users"` NumClients int32 `json:"num_clients"` }
PresenceStatsResult is a result of info command.
type Publication ¶
type Publication struct { UID string `json:"uid"` Info *ClientInfo `json:"info"` Channel string `json:"channel"` Data json.RawMessage `json:"data"` Client string `json:"client"` }
Publication represents message published into channel.
type Reply ¶
type Reply struct { Error *Error `json:"error"` Result json.RawMessage `json:"result"` }
Reply is a server response to command.