From dc6494d20c776b05a9bdfb86b290ae4afbe68752 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Tue, 14 Mar 2023 16:08:19 -0400 Subject: [PATCH] main: sometimes events can be errors Signed-off-by: Vincent Batts --- main.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 60ca580..68d67be 100644 --- a/main.go +++ b/main.go @@ -73,14 +73,19 @@ func main() { for { select { case e := <-evnt: - ue := e.(*mastodon.UpdateEvent) - - // https://pkg.go.dev/github.com/mattn/go-mastodon#Status - buf, err := json.MarshalIndent(ue.Status, "", " ") - if err != nil { - logrus.Error(err) + switch v := e.(type) { + case nil: + logrus.Info("event is nil") + case *mastodon.UpdateEvent: + // https://pkg.go.dev/github.com/mattn/go-mastodon#Status + buf, err := json.MarshalIndent(v.Status, "", " ") + if err != nil { + logrus.Error(err) + } + fmt.Println(string(buf)) + case *mastodon.ErrorEvent: + logrus.Errorf("event was error: %#v", v) } - fmt.Println(string(buf)) } } }