From 1ef37780512e6bf6b1f35602d3fc8620a83f13a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=2E=20Mert=20Y=C4=B1ld=C4=B1ran?= Date: Wed, 8 Dec 2021 16:53:57 +0300 Subject: [PATCH] Add type switch for `Base` field of `MizuEntry` (#520) --- agent/pkg/api/socket_routes.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/agent/pkg/api/socket_routes.go b/agent/pkg/api/socket_routes.go index 8feccebac..a96bb11ff 100644 --- a/agent/pkg/api/socket_routes.go +++ b/agent/pkg/api/socket_routes.go @@ -127,8 +127,15 @@ func websocketHandler(w http.ResponseWriter, r *http.Request, eventHandlers Even var dataMap map[string]interface{} err = json.Unmarshal(bytes, &dataMap) - base := dataMap["base"].(map[string]interface{}) - base["id"] = uint(dataMap["id"].(float64)) + var base map[string]interface{} + switch dataMap["base"].(type) { + case map[string]interface{}: + base = dataMap["base"].(map[string]interface{}) + base["id"] = uint(dataMap["id"].(float64)) + default: + logger.Log.Debugf("Base field has an unrecognized type: %+v", dataMap) + continue + } baseEntryBytes, _ := models.CreateBaseEntryWebSocketMessage(base) SendToSocket(socketId, baseEntryBytes)