Esempio n. 1
0
// robots returns route handler.
// Writes JSON with robots representation
func (a *API) robots(res http.ResponseWriter, req *http.Request) {
	jsonRobots := []*gobot.JSONRobot{}
	a.master.Robots().Each(func(r *gobot.Robot) {
		jsonRobots = append(jsonRobots, gobot.NewJSONRobot(r))
	})
	a.writeJSON(map[string]interface{}{"robots": jsonRobots}, res)
}
Esempio n. 2
0
func (a *API) jsonRobotFor(name string) (jrobot *gobot.JSONRobot, err error) {
	if robot := a.master.Robot(name); robot != nil {
		jrobot = gobot.NewJSONRobot(robot)
	} else {
		err = errors.New("No Robot found with the name " + name)
	}
	return
}