Ejemplo n.º 1
0
func (a *API) jsonDeviceFor(robot string, name string) (jdevice *gobot.JSONDevice, err error) {
	if device := a.master.Robot(robot).Device(name); device != nil {
		jdevice = gobot.NewJSONDevice(device)
	} else {
		err = errors.New("No Device found with the name " + name)
	}
	return
}
Ejemplo n.º 2
0
// robotDevices returns devices route handler.
// Writes JSON with robot devices representation
func (a *API) robotDevices(res http.ResponseWriter, req *http.Request) {
	if robot := a.master.Robot(req.URL.Query().Get(":robot")); robot != nil {
		jsonDevices := []*gobot.JSONDevice{}
		robot.Devices().Each(func(d gobot.Device) {
			jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d))
		})
		a.writeJSON(map[string]interface{}{"devices": jsonDevices}, res)
	} else {
		a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res)
	}
}