Fix Client API

This commit is contained in:
James Mills 2022-03-28 01:31:57 +10:00
parent e954f2f47f
commit 5fe134909b
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
2 changed files with 9 additions and 17 deletions

View File

@ -7,7 +7,6 @@ import (
"fmt"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
@ -74,18 +73,6 @@ func NewClient(url string, options *Options) *Client {
return client
}
// Handle ...
func (c *Client) Handle(msg *msgbus.Message) error {
out, err := json.Marshal(msg)
if err != nil {
return err
}
os.Stdout.Write(out)
os.Stdout.Write([]byte{'\r', '\n'})
return nil
}
// Pull ...
func (c *Client) Pull(topic string) (msg *msgbus.Message, err error) {
c.RLock()
@ -113,9 +100,6 @@ func (c *Client) Pull(topic string) (msg *msgbus.Message, err error) {
if err := json.NewDecoder(res.Body).Decode(&msg); err != nil {
return nil, err
}
if err := c.Handle(msg); err != nil {
return nil, err
}
return msg, nil
}

View File

@ -1,6 +1,9 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -38,5 +41,10 @@ func pull(client *client.Client, topic string) {
topic = defaultTopic
}
client.Pull(topic)
msg, err := client.Pull(topic)
if err != nil {
fmt.Fprintf(os.Stderr, "error reading message: %s\n", err)
os.Exit(2)
}
fmt.Printf("%s\n", msg.Payload)
}