示例#1
0
文件: api.go 项目: hybridgroup/gobot
// 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)
}
示例#2
0
文件: api.go 项目: hybridgroup/gobot
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
}