コード例 #1
0
ファイル: api.go プロジェクト: ympons/gobot
func (a *API) jsonConnectionFor(robot string, name string) (jconnection *gobot.JSONConnection, err error) {
	if connection := a.gobot.Robot(robot).Connection(name); connection != nil {
		jconnection = gobot.NewJSONConnection(connection)
	} else {
		err = errors.New("No Connection found with the name " + name)
	}
	return
}
コード例 #2
0
ファイル: api.go プロジェクト: ympons/gobot
// robotConnections returns connections route handler
// writes JSON with robot connections representation
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) {
	jsonConnections := []*gobot.JSONConnection{}
	if robot := a.gobot.Robot(req.URL.Query().Get(":robot")); robot != nil {
		robot.Connections().Each(func(c gobot.Connection) {
			jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c))
		})
		a.writeJSON(map[string]interface{}{"connections": jsonConnections}, res)
	} else {
		a.writeJSON(map[string]interface{}{"error": "No Robot found with the name " + req.URL.Query().Get(":robot")}, res)
	}

}