The Hop server side Go Leap client allows you to interact with Leap from a server. This can be useful for things such as microservices where you wish to dispatch events to many nodes.
hop-go
, our Go SDK:
MessageEventChannel
method and then loop around the channel. It is very
important with these channels that you listen for the ok signal since the
channel might be closed if the client is not reconnecting after an error or if
it was closed.
When we use the channels, we will want to create it once and then use it. By
nature of how it is implemented, if you need the events in 2 different places,
you can call this function in multiple goroutines and get seperate channels that
return the same content:
Data
field on the event contains a
map with the JSON data in, the EventName
field contains the event name, and
ChannelID
contains the channel ID or is blank if this is a direct message.
ChannelEventChannel
method and then loop around the channel. It is very
important with these channels that you listen for the ok signal since the
channel might be closed if the client is not reconnecting after an error or if
it was closed.
When we use the channels, we will want to create it once and then use it. By
nature of how it is implemented, if you need the events in 2 different places,
you can call this function in multiple goroutines and get seperate channels that
return the same content:
any
. The reason for this is that channel events can be a variety of different
things. We will want to switch on the type:
AddStateUpdateListener
function. This
takes a function which we can use to watch the state:
Connect
method:
err
param. This
param can be nil, so this is a consideration you should keep in mind when you
are logging:
leap.NewFmtLogger()
. The
logging level is controlled by the HOP_LOGGING_LEVEL
environment variable. The
default is info
. The levels are debug
, info
, warn
, and error
. To
prevent unexpected behaviour, if the logger is nil, a NopLogger will be made and
nothing will be logged.