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