Channel

Channel represents a WebSocket channel with identity, members and own handlers.

This API is used in WebSocket Channels.


Symbols

SymbolClassDescription
ChanneltypeChannel defines a public type of API.
ChannelHandlertypeChannelHandler defines a public type of API.
NewChannelfuncBuild NewChannel.
Channel.GenerationVersionfuncReturns the version of the active generation.
Channel.IDfuncReturn the identifier.
Channel.NamefuncGive the name back.
Channel.KeyfuncReturns the logical key.
Channel.MembersfuncGive back the member sockets.
Channel.CountfuncReturns the number of keys or elements available.
Channel.HasfuncIt indicates whether the collection contains the key.
Channel.EmitfuncIt emits an event.
Channel.LeavefuncTake the socket back.
Channel.ClosefuncClose the open resources.
Channel.IsClosedfuncIndicates the state of IsClosed.
Channel.WhenfuncSearch a previous handler.
Channel.OnfuncHe records an event handler.
Channel.OnNamedfuncHe records a handler with parameter names.
Channel.OnRegisteredfuncHe registers a handler with his full signature.
Channel.DispatchWhenfuncOffice DispatchWhen.
Channel.DispatchOnfuncOffice DispatchOn.
Channel.OnSignaturefuncReturns the registered signature for an event.
Channel.OnParameterTypesfuncReturns the types of parameters recorded.
Channel.OnParameterNamesfuncReturns the names of registered parameters.
Channel.WhenParameterTypesfuncGive back the guys from the previous handler.
ChannelRegistrytypeChannelRegistry defines a public type of API.
ChannelsvarChannels it exposes a shared value of the package.
ChannelRegistry.GetfuncIt gets the first value associated with a key.
ChannelRegistry.HasfuncIt indicates whether the collection contains the key.
ChannelRegistry.ListfuncReturns List.
ChannelRegistry.CountfuncReturns the number of keys or elements available.

Channel

Declaration:

gox
type Channel struct {
	// contiene campos internos
}

Channel defines a public type of API.


ChannelHandler

Declaration:

gox
type ChannelHandler func(channel *Channel)

ChannelHandler defines a public type of API.


NewChannel

Declaration:

gox
func NewChannel(id, name, key string) *Channel

Build NewChannel.

Parameters

ParameterTypeDescription
``idType value id required by the operation.
``nameType value name required by the operation.
keystringKey that identifies the value.

Returns

ReturnTypeDescription
value*ChannelType value *Channel produced by the operation.

Usage syntax

gox
value := gox.NewChannel("id", "name", "key")

Channel.GenerationVersion

Declaration:

gox
func (channel *Channel) GenerationVersion() string

Returns the version of the active generation.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := channel.GenerationVersion()

Channel.ID

Declaration:

gox
func (channel *Channel) ID() string

Return the identifier.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := channel.ID()

Channel.Name

Declaration:

gox
func (channel *Channel) Name() string

Give the name back.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := channel.Name()

Channel.Key

Declaration:

gox
func (channel *Channel) Key() string

Returns the logical key.

Returns

ReturnTypeDescription
valuestringTextual value produced by the operation; its zero value is an empty string.

Usage syntax

gox
value := channel.Key()

Channel.Members

Declaration:

gox
func (channel *Channel) Members() SocketCollection

Give back the member sockets.

Returns

ReturnTypeDescription
valueSocketCollectionType value SocketCollection produced by the operation.

Usage syntax

gox
value := channel.Members()

Channel.Count

Declaration:

gox
func (channel *Channel) Count() int

Returns the number of keys or elements available.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := channel.Count()

Channel.Has

Declaration:

gox
func (channel *Channel) Has(socket *Socket) bool

It indicates whether the collection contains the key.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := channel.Has(nil)

Channel.Emit

Declaration:

gox
func (channel *Channel) Emit(event string, values ...any)

It emits an event.

Parameters

ParameterTypeDescription
eventstringName of the event.
values...anyValues provided to the operation.

Usage syntax

gox
channel.Emit("event", value)

Channel.Leave

Declaration:

gox
func (channel *Channel) Leave(socket *Socket) error

Take the socket back.

Parameters

ParameterTypeDescription
socket*SocketType value *Socket required by the operation.

Returns

ReturnTypeDescription
errerrornil 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

gox
err := channel.Leave(nil)

Channel.Close

Declaration:

gox
func (channel *Channel) Close() error

Close the open resources.

Returns

ReturnTypeDescription
errerrornil 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

gox
err := channel.Close()

Channel.IsClosed

Declaration:

gox
func (channel *Channel) IsClosed() bool

Indicates the state of IsClosed.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := channel.IsClosed()

Channel.When

Declaration:

gox
func (channel *Channel) When(event string, handler any)

Search a previous handler.

Parameters

ParameterTypeDescription
eventstringName of the event.
handleranyType value any required by the operation.

Usage syntax

gox
channel.When("event", nil)

Channel.On

Declaration:

gox
func (channel *Channel) On(event string, handler any)

He records an event handler.

Parameters

ParameterTypeDescription
eventstringName of the event.
handleranyType value any required by the operation.

Usage syntax

gox
channel.On("event", nil)

Channel.OnNamed

Declaration:

gox
func (channel *Channel) OnNamed(event string, parameterNames []string, handler any)

He records a handler with parameter names.

Parameters

ParameterTypeDescription
eventstringName of the event.
parameterNames[]stringType value []string required by the operation.
handleranyType value any required by the operation.

Usage syntax

gox
channel.OnNamed("event", value, nil)

Channel.OnRegistered

Declaration:

gox
func (channel *Channel) OnRegistered(event string, parameterNames []string, hasReply bool, handler any)

He registers a handler with his full signature.

Parameters

ParameterTypeDescription
eventstringName of the event.
parameterNames[]stringType value []string required by the operation.
hasReplyboolType value bool required by the operation.
handleranyType value any required by the operation.

Usage syntax

gox
channel.OnRegistered("event", value, value, nil)

Channel.DispatchWhen

Declaration:

gox
func (channel *Channel) DispatchWhen(event string, args ...any) (any, bool, error)

Office DispatchWhen.

Parameters

ParameterTypeDescription
eventstringName of the event.
args...anyType value ...any required by the operation.

Returns

ReturnTypeDescription
valueanyType value any produced by the operation.
okboolIt indicates the result of the check.
errerrornil 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:

gox
func (channel *Channel) DispatchOn(event string, args ...any) (any, bool, error)

Office DispatchOn.

Parameters

ParameterTypeDescription
eventstringName of the event.
args...anyType value ...any required by the operation.

Returns

ReturnTypeDescription
valueanyType value any produced by the operation.
okboolIt indicates the result of the check.
errerrornil 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:

gox
func (channel *Channel) OnSignature(event string) (WSEventSignature, bool)

Returns the registered signature for an event.

Parameters

ParameterTypeDescription
eventstringName of the event.

Returns

ReturnTypeDescription
valueWSEventSignatureType value WSEventSignature produced by the operation.
okboolIt indicates the result of the check.

Usage syntax

gox
value, ok := channel.OnSignature("event")

Channel.OnParameterTypes

Declaration:

gox
func (channel *Channel) OnParameterTypes(event string) ([]reflect.Type, bool, error)

Returns the types of parameters recorded.

Parameters

ParameterTypeDescription
eventstringName of the event.

Returns

ReturnTypeDescription
value[]reflect.TypeResult collection; can be nil when there are no values.
okboolIt indicates the result of the check.
errerrornil 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

gox
value, ok, err := channel.OnParameterTypes("event")

Channel.OnParameterNames

Declaration:

gox
func (channel *Channel) OnParameterNames(event string) ([]string, bool)

Returns the names of registered parameters.

Parameters

ParameterTypeDescription
eventstringName of the event.

Returns

ReturnTypeDescription
value[]stringResult collection; can be nil when there are no values.
okboolIt indicates the result of the check.

Usage syntax

gox
value, ok := channel.OnParameterNames("event")

Channel.WhenParameterTypes

Declaration:

gox
func (channel *Channel) WhenParameterTypes(event string) ([]reflect.Type, bool, error)

Give back the guys from the previous handler.

Parameters

ParameterTypeDescription
eventstringName of the event.

Returns

ReturnTypeDescription
value[]reflect.TypeResult collection; can be nil when there are no values.
okboolIt indicates the result of the check.
errerrornil 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

gox
value, ok, err := channel.WhenParameterTypes("event")

ChannelRegistry

Declaration:

gox
type ChannelRegistry struct{ state *channelRegistryState }

ChannelRegistry defines a public type of API.


Channels

Declaration:

gox
var Channels = &ChannelRegistry{state: &channelRegistryState{}}

Channels it exposes a shared value of the package.


ChannelRegistry.Get

Declaration:

gox
func (registry *ChannelRegistry) Get(id string) (*Channel, bool)

It gets the first value associated with a key.

Parameters

ParameterTypeDescription
idstringType value string required by the operation.

Returns

ReturnTypeDescription
value*ChannelType value *Channel produced by the operation.
okboolIt indicates the result of the check.

Behavior

When the key does not exist, it returns the zero value of T and false.

Usage syntax

gox
value, ok := channelRegistry.Get("id")

ChannelRegistry.Has

Declaration:

gox
func (registry *ChannelRegistry) Has(id string) bool

It indicates whether the collection contains the key.

Parameters

ParameterTypeDescription
idstringType value string required by the operation.

Returns

ReturnTypeDescription
valueboolIt indicates the result of the check.

Usage syntax

gox
value := channelRegistry.Has("id")

ChannelRegistry.List

Declaration:

gox
func (registry *ChannelRegistry) List() []*Channel

Returns List.

Returns

ReturnTypeDescription
value[]*ChannelResult collection; can be nil when there are no values.

Usage syntax

gox
value := channelRegistry.List()

ChannelRegistry.Count

Declaration:

gox
func (registry *ChannelRegistry) Count() int

Returns the number of keys or elements available.

Returns

ReturnTypeDescription
valueintType value int produced by the operation.

Usage syntax

gox
value := channelRegistry.Count()

See also

Next step

Continue with errors and closing codes.

WebSocket errors