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
This commit is contained in:
tidwall 2019-10-28 12:51:44 -07:00
parent d2cfb87c89
commit 10f7bfc445
2 changed files with 4 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import (
"net" "net"
"sync" "sync"
"github.com/tidwall/redcon"
"github.com/tidwall/tile38/internal/log" "github.com/tidwall/tile38/internal/log"
) )
@ -160,9 +161,9 @@ func (server *Server) goLive(
var livemsg []byte var livemsg []byte
switch outputType { switch outputType {
case JSON: case JSON:
livemsg = []byte(`{"ok":true,"live":true}`) livemsg = redcon.AppendBulkString(nil, `{"ok":true,"live":true}`)
case RESP: case RESP:
livemsg = []byte("+OK\r\n") livemsg = redcon.AppendOK(nil)
} }
if err := writeLiveMessage(conn, livemsg, false, connType, websocket); err != nil { if err := writeLiveMessage(conn, livemsg, false, connType, websocket); err != nil {
return nil // nil return is fine here return nil // nil return is fine here

View File

@ -194,7 +194,7 @@ func (c *Server) liveSubscription(
write := func(data []byte) { write := func(data []byte) {
writeLock.Lock() writeLock.Lock()
defer writeLock.Unlock() defer writeLock.Unlock()
writeLiveMessage(conn, data, false, connType, websocket) writeLiveMessage(conn, data, outputType == JSON, connType, websocket)
} }
writeOK := func() { writeOK := func() {
switch outputType { switch outputType {