diff --git a/tg/broker.go b/tg/broker.go index 9ebd1d4..90792fb 100644 --- a/tg/broker.go +++ b/tg/broker.go @@ -34,8 +34,8 @@ func (b *Broker) Close() { b.Socket.Close() } -// SendTextMessage sends a HTML-styles text message to a specific chat -// A reply_to message ID can be specified as optional parameter +// SendTextMessage sends a HTML-styles text message to a specific chat. +// A reply_to message ID can be specified as optional parameter. func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) { cmd := ClientCommand{ Type: CmdSendTextMessage, @@ -53,16 +53,16 @@ func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) { fmt.Fprintln(b.Socket, string(data)) } -// GetFile sends a file retrieval request to the Broker -// This function is asynchronous as data will be delivered to the given callback +// GetFile sends a file retrieval request to the Broker. +// This function is asynchronous as data will be delivered to the given callback. func (b *Broker) GetFile(fileID string, fn BrokerCallback) int { cid := b.RegisterCallback(fn) // Make file request return cid } -// RegisterCallback assigns a callback ID to the given callback and puts it on the callback list -// This function should never be called by clients +// RegisterCallback assigns a callback ID to the given callback and puts it on the callback list. +// This function should never be called by clients. func (b *Broker) RegisterCallback(fn BrokerCallback) int { cblen := len(b.Callbacks) // List is full, append to end @@ -84,8 +84,8 @@ func (b *Broker) RegisterCallback(fn BrokerCallback) int { return id } -// RemoveCallback removes a callback from the callback list by ID -// This function should never be called by clients +// RemoveCallback removes a callback from the callback list by ID. +// This function should never be called by clients. func (b *Broker) RemoveCallback(id int) { b.Callbacks[id] = nil if id < b.cbFree { @@ -94,8 +94,8 @@ func (b *Broker) RemoveCallback(id int) { b.resizeCbArray() } -// SpliceCallback retrieves a callback by ID and removes it from the list -// This function should never be called by clients +// SpliceCallback retrieves a callback by ID and removes it from the list. +// This function should never be called by clients. func (b *Broker) SpliceCallback(id int) BrokerCallback { defer b.RemoveCallback(id) return b.Callbacks[id] diff --git a/tg/client.go b/tg/client.go index 95fe387..1fab367 100644 --- a/tg/client.go +++ b/tg/client.go @@ -13,8 +13,8 @@ type UpdateHandler func(broker *Broker, message APIMessage) // BrokerCallback is a callback for broker responses to client requests type BrokerCallback func(broker *Broker, update BrokerUpdate) -// CreateBrokerClient creates a connection to a broker and sends all webhook updates to a given function -// This is the intended way to create clients, please refer to examples for how to make a simple client +// CreateBrokerClient creates a connection to a broker and sends all webhook updates to a given function. +// This is the intended way to create clients, please refer to examples for how to make a simple client. func CreateBrokerClient(brokerAddr string, updateFn UpdateHandler) error { broker, err := ConnectToBroker(brokerAddr) if err != nil { diff --git a/tg/client_test.go b/tg/client_test.go index 4c4595e..6f7d39d 100644 --- a/tg/client_test.go +++ b/tg/client_test.go @@ -1,4 +1,4 @@ -package tg +package tg_test // This function creates a basic client that connects to a broker and checks for message containing greetings. // If it finds a greeting message it will greet back the user (using the reply_to parameter)