Closed glaslos closed 8 months ago
Hii @glaslos , I am exited to work on this issue . Meanwhile if i run backend server locally what arguments do i need to pass with "go run server.go" to pass token middleware .
Can you check if my approach is correct to address this issue .
Yes, that sound about right. Maybe try without defining the Event type too specific, maybe a map[string]interface{}
does the trick here.
Please check if my snippet is correct and let me know how can i test this , i mean how these endpoints will be called when i run locally go server. afterward i will generate PR.
At line
I will put this below snippet in action :
`// Unmarshal the JSON message into a map var data map[string]interface{} if err := json.Unmarshal(msg, &data); err != nil { http.Error(w, "Invalid JSON payload", http.StatusBadRequest) return }
// Check if "sensorID" key exists
if sensorID, ok := data["sensorID"].(string); ok {
// Manipulate the "sensorID"
sensorID = splitSensorID(sensorID)
// Update the map with the new "sensorID" value
data["sensorID"] = sensorID
}
// Marshal the map back to a JSON message
alteredMsg , err := json.Marshal(data)
if err != nil {
http.Error(w, "Error processing JSON", http.StatusInternalServerError)
return
}
cs.publish(alteredMsg)
//Helper function which splits into two parts the sensorID by the hyphen func splitSensorID(sensorID string) string { parts := strings.Split(sensorID, "-") if len(parts) > 0 { return parts[0] } return sensorID // Return the original sensorID if there's no hyphen }`
Yes, this looks good!
I was curious to know , why havn't we implemented Lint , and designed test cases for both Frontend and backend . Let me if maintainers are looking into this field . I would be happy to implement these .
I will add linting in the GitHub actions in the future. Considering we are only a few people working in this at the moment, we didn't consider it a priority. Same for the testing, right now we do a lot of manual tests before we release. But feel free to add more tests!
Before publishing to the websockets, truncate the sensor UUID to only the first part until the first
-
. Remove truncating from the front-end code.