From 10f7bfc445ee3deffad7e8ee76419d6a0045c80c Mon Sep 17 00:00:00 2001 From: tidwall Date: Mon, 28 Oct 2019 12:51:44 -0700 Subject: [PATCH] Fix invalid pubsub format for json output This commit fixes a bug that causes bad formatting for geofence notifications when a client's output is set to JSON. closes #499 --- internal/server/live.go | 5 +++-- internal/server/pubsub.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/server/live.go b/internal/server/live.go index 0331594a..ab1d6410 100644 --- a/internal/server/live.go +++ b/internal/server/live.go @@ -8,6 +8,7 @@ import ( "net" "sync" + "github.com/tidwall/redcon" "github.com/tidwall/tile38/internal/log" ) @@ -160,9 +161,9 @@ func (server *Server) goLive( var livemsg []byte switch outputType { case JSON: - livemsg = []byte(`{"ok":true,"live":true}`) + livemsg = redcon.AppendBulkString(nil, `{"ok":true,"live":true}`) case RESP: - livemsg = []byte("+OK\r\n") + livemsg = redcon.AppendOK(nil) } if err := writeLiveMessage(conn, livemsg, false, connType, websocket); err != nil { return nil // nil return is fine here diff --git a/internal/server/pubsub.go b/internal/server/pubsub.go index d6d8ff3e..4cdf0b8f 100644 --- a/internal/server/pubsub.go +++ b/internal/server/pubsub.go @@ -194,7 +194,7 @@ func (c *Server) liveSubscription( write := func(data []byte) { writeLock.Lock() defer writeLock.Unlock() - writeLiveMessage(conn, data, false, connType, websocket) + writeLiveMessage(conn, data, outputType == JSON, connType, websocket) } writeOK := func() { switch outputType {