1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-17 04:30:03 +02:00

api/client.go: implement Client.Subscribe correctly by returning a error on unsupported channel type.

This commit is contained in:
Henrik Hautakoski 2023-05-26 14:09:47 +02:00
parent 9e586d879d
commit 8154bee1c2
2 changed files with 35 additions and 3 deletions

View file

@ -1,6 +1,7 @@
package api
import (
"fmt"
"sync"
"github.com/eosswedenorg/thalos/api/message"
@ -63,13 +64,16 @@ func (c *Client) hbHandler(payload []byte) {
c.OnHeartbeat(hb)
}
func (c *Client) Subscribe(channel Channel) {
func (c *Client) Subscribe(channel Channel) error {
var handler handler
if HeartbeatChannel.Is(channel) {
switch t := channel.Type(); t {
case HeartbeatChannel.Type():
handler = c.hbHandler
} else {
case ActionChannel{}.Channel().Type():
handler = c.actHandler
default:
return fmt.Errorf("invalid channel type. %s", t)
}
// Start a worker for this channel.
@ -78,6 +82,8 @@ func (c *Client) Subscribe(channel Channel) {
defer c.wg.Done()
c.worker(channel, handler)
}()
return nil
}
func (c *Client) Run() {