Channel
Channel represents a WebSocket channel with identity, members and own handlers.
This API is used in WebSocket Channels.
Symbols
| Symbol | Class | Description |
|---|---|---|
| Channel | type | Channel defines a public type of API. |
| ChannelHandler | type | ChannelHandler defines a public type of API. |
| NewChannel | func | Build NewChannel. |
| Channel.GenerationVersion | func | Returns the version of the active generation. |
| Channel.ID | func | Return the identifier. |
| Channel.Name | func | Give the name back. |
| Channel.Key | func | Returns the logical key. |
| Channel.Members | func | Give back the member sockets. |
| Channel.Count | func | Returns the number of keys or elements available. |
| Channel.Has | func | It indicates whether the collection contains the key. |
| Channel.Emit | func | It emits an event. |
| Channel.Leave | func | Take the socket back. |
| Channel.Close | func | Close the open resources. |
| Channel.IsClosed | func | Indicates the state of IsClosed. |
| Channel.When | func | Search a previous handler. |
| Channel.On | func | He records an event handler. |
| Channel.OnNamed | func | He records a handler with parameter names. |
| Channel.OnRegistered | func | He registers a handler with his full signature. |
| Channel.DispatchWhen | func | Office DispatchWhen. |
| Channel.DispatchOn | func | Office DispatchOn. |
| Channel.OnSignature | func | Returns the registered signature for an event. |
| Channel.OnParameterTypes | func | Returns the types of parameters recorded. |
| Channel.OnParameterNames | func | Returns the names of registered parameters. |
| Channel.WhenParameterTypes | func | Give back the guys from the previous handler. |
| ChannelRegistry | type | ChannelRegistry defines a public type of API. |
| Channels | var | Channels it exposes a shared value of the package. |
| ChannelRegistry.Get | func | It gets the first value associated with a key. |
| ChannelRegistry.Has | func | It indicates whether the collection contains the key. |
| ChannelRegistry.List | func | Returns List. |
| ChannelRegistry.Count | func | Returns the number of keys or elements available. |
Channel
Declaration:
type Channel struct {
// contiene campos internos
} Channel defines a public type of API.
ChannelHandler
Declaration:
type ChannelHandler func(channel *Channel) ChannelHandler defines a public type of API.
NewChannel
Declaration:
func NewChannel(id, name, key string) *Channel Build NewChannel.
Parameters
| Parameter | Type | Description |
|---|---|---|
| `` | id | Type value id required by the operation. |
| `` | name | Type value name required by the operation. |
key | string | Key that identifies the value. |
Returns
| Return | Type | Description |
|---|---|---|
value | *Channel | Type value *Channel produced by the operation. |
Usage syntax
value := gox.NewChannel("id", "name", "key") Channel.GenerationVersion
Declaration:
func (channel *Channel) GenerationVersion() string Returns the version of the active generation.
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
Usage syntax
value := channel.GenerationVersion() Channel.ID
Declaration:
func (channel *Channel) ID() string Return the identifier.
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
Usage syntax
value := channel.ID() Channel.Name
Declaration:
func (channel *Channel) Name() string Give the name back.
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
Usage syntax
value := channel.Name() Channel.Key
Declaration:
func (channel *Channel) Key() string Returns the logical key.
Returns
| Return | Type | Description |
|---|---|---|
value | string | Textual value produced by the operation; its zero value is an empty string. |
Usage syntax
value := channel.Key() Channel.Members
Declaration:
func (channel *Channel) Members() SocketCollection Give back the member sockets.
Returns
| Return | Type | Description |
|---|---|---|
value | SocketCollection | Type value SocketCollection produced by the operation. |
Usage syntax
value := channel.Members() Channel.Count
Declaration:
func (channel *Channel) Count() int Returns the number of keys or elements available.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := channel.Count() Channel.Has
Declaration:
func (channel *Channel) Has(socket *Socket) bool It indicates whether the collection contains the key.
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | *Socket | Type value *Socket required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := channel.Has(nil) Channel.Emit
Declaration:
func (channel *Channel) Emit(event string, values ...any) It emits an event.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
values | ...any | Values provided to the operation. |
Usage syntax
channel.Emit("event", value) Channel.Leave
Declaration:
func (channel *Channel) Leave(socket *Socket) error Take the socket back.
Parameters
| Parameter | Type | Description |
|---|---|---|
socket | *Socket | Type value *Socket required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The operation returns an error when it cannot complete the above contract.
Errors
Leave returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Usage syntax
err := channel.Leave(nil) Channel.Close
Declaration:
func (channel *Channel) Close() error Close the open resources.
Returns
| Return | Type | Description |
|---|---|---|
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The subsequent calls depend on the state of the appeal.
Errors
Close returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Usage syntax
err := channel.Close() Channel.IsClosed
Declaration:
func (channel *Channel) IsClosed() bool Indicates the state of IsClosed.
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := channel.IsClosed() Channel.When
Declaration:
func (channel *Channel) When(event string, handler any) Search a previous handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
handler | any | Type value any required by the operation. |
Usage syntax
channel.When("event", nil) Channel.On
Declaration:
func (channel *Channel) On(event string, handler any) He records an event handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
handler | any | Type value any required by the operation. |
Usage syntax
channel.On("event", nil) Channel.OnNamed
Declaration:
func (channel *Channel) OnNamed(event string, parameterNames []string, handler any) He records a handler with parameter names.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
parameterNames | []string | Type value []string required by the operation. |
handler | any | Type value any required by the operation. |
Usage syntax
channel.OnNamed("event", value, nil) Channel.OnRegistered
Declaration:
func (channel *Channel) OnRegistered(event string, parameterNames []string, hasReply bool, handler any) He registers a handler with his full signature.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
parameterNames | []string | Type value []string required by the operation. |
hasReply | bool | Type value bool required by the operation. |
handler | any | Type value any required by the operation. |
Usage syntax
channel.OnRegistered("event", value, value, nil) Channel.DispatchWhen
Declaration:
func (channel *Channel) DispatchWhen(event string, args ...any) (any, bool, error) Office DispatchWhen.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
args | ...any | Type value ...any required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | any | Type value any produced by the operation. |
ok | bool | It indicates the result of the check. |
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The operation returns an error when it cannot complete the above contract.
Errors
DispatchWhen returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Channel.DispatchOn
Declaration:
func (channel *Channel) DispatchOn(event string, args ...any) (any, bool, error) Office DispatchOn.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
args | ...any | Type value ...any required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | any | Type value any produced by the operation. |
ok | bool | It indicates the result of the check. |
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The operation returns an error when it cannot complete the above contract.
Errors
DispatchOn returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Channel.OnSignature
Declaration:
func (channel *Channel) OnSignature(event string) (WSEventSignature, bool) Returns the registered signature for an event.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
Returns
| Return | Type | Description |
|---|---|---|
value | WSEventSignature | Type value WSEventSignature produced by the operation. |
ok | bool | It indicates the result of the check. |
Usage syntax
value, ok := channel.OnSignature("event") Channel.OnParameterTypes
Declaration:
func (channel *Channel) OnParameterTypes(event string) ([]reflect.Type, bool, error) Returns the types of parameters recorded.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
Returns
| Return | Type | Description |
|---|---|---|
value | []reflect.Type | Result collection; can be nil when there are no values. |
ok | bool | It indicates the result of the check. |
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The operation returns an error when it cannot complete the above contract.
Errors
OnParameterTypes returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Usage syntax
value, ok, err := channel.OnParameterTypes("event") Channel.OnParameterNames
Declaration:
func (channel *Channel) OnParameterNames(event string) ([]string, bool) Returns the names of registered parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
Returns
| Return | Type | Description |
|---|---|---|
value | []string | Result collection; can be nil when there are no values. |
ok | bool | It indicates the result of the check. |
Usage syntax
value, ok := channel.OnParameterNames("event") Channel.WhenParameterTypes
Declaration:
func (channel *Channel) WhenParameterTypes(event string) ([]reflect.Type, bool, error) Give back the guys from the previous handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Name of the event. |
Returns
| Return | Type | Description |
|---|---|---|
value | []reflect.Type | Result collection; can be nil when there are no values. |
ok | bool | It indicates the result of the check. |
err | error | nil if the operation ends correctly; otherwise, the error produced. |
Behavior
The operation returns an error when it cannot complete the above contract.
Errors
WhenParameterTypes returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.
Usage syntax
value, ok, err := channel.WhenParameterTypes("event") ChannelRegistry
Declaration:
type ChannelRegistry struct{ state *channelRegistryState } ChannelRegistry defines a public type of API.
Channels
Declaration:
var Channels = &ChannelRegistry{state: &channelRegistryState{}} Channels it exposes a shared value of the package.
ChannelRegistry.Get
Declaration:
func (registry *ChannelRegistry) Get(id string) (*Channel, bool) It gets the first value associated with a key.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Type value string required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | *Channel | Type value *Channel produced by the operation. |
ok | bool | It indicates the result of the check. |
Behavior
When the key does not exist, it returns the zero value of T and false.
Usage syntax
value, ok := channelRegistry.Get("id") ChannelRegistry.Has
Declaration:
func (registry *ChannelRegistry) Has(id string) bool It indicates whether the collection contains the key.
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Type value string required by the operation. |
Returns
| Return | Type | Description |
|---|---|---|
value | bool | It indicates the result of the check. |
Usage syntax
value := channelRegistry.Has("id") ChannelRegistry.List
Declaration:
func (registry *ChannelRegistry) List() []*Channel Returns List.
Returns
| Return | Type | Description |
|---|---|---|
value | []*Channel | Result collection; can be nil when there are no values. |
Usage syntax
value := channelRegistry.List() ChannelRegistry.Count
Declaration:
func (registry *ChannelRegistry) Count() int Returns the number of keys or elements available.
Returns
| Return | Type | Description |
|---|---|---|
value | int | Type value int produced by the operation. |
Usage syntax
value := channelRegistry.Count()