예제 #1
0
파일: api.go 프로젝트: hybridgroup/gobot
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
}
예제 #2
0
파일: api.go 프로젝트: hybridgroup/gobot
// 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)
	}
}