Git Product home page Git Product logo

Comments (8)

Tushar-kalsi avatar Tushar-kalsi commented on June 19, 2024

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 .

from ochi.

glaslos avatar glaslos commented on June 19, 2024

You can just use make or copy the command from here

from ochi.

Tushar-kalsi avatar Tushar-kalsi commented on June 19, 2024

Can you check if my approach is correct to address this issue .

  • Intercept the msg variable from here .
  • Decode this msg []byte back to go object by taking reference of Event interface used in frontend .
  • Pull out sensorID from this object .
  • Alter it according to conditions.
  • Convert back into []byte.
  • Call cs.publish function .

from ochi.

glaslos avatar glaslos commented on June 19, 2024

Yes, that sound about right. Maybe try without defining the Event type too specific, maybe a map[string]interface{} does the trick here.

from ochi.

Tushar-kalsi avatar Tushar-kalsi commented on June 19, 2024

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
}`

from ochi.

glaslos avatar glaslos commented on June 19, 2024

Yes, this looks good!

from ochi.

Tushar-kalsi avatar Tushar-kalsi commented on June 19, 2024

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 .

from ochi.

glaslos avatar glaslos commented on June 19, 2024

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!

from ochi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.