@@ -17,7 +17,7 @@ import (
17
17
18
18
// API represents an API server
19
19
type API struct {
20
- master * gobot.Master
20
+ manager * gobot.Manager
21
21
router * pat.PatternServeMux
22
22
Host string
23
23
Port string
@@ -28,11 +28,11 @@ type API struct {
28
28
}
29
29
30
30
// NewAPI returns a new api instance
31
- func NewAPI (m * gobot.Master ) * API {
31
+ func NewAPI (m * gobot.Manager ) * API {
32
32
return & API {
33
- master : m ,
34
- router : pat .New (),
35
- Port : "3000" ,
33
+ manager : m ,
34
+ router : pat .New (),
35
+ Port : "3000" ,
36
36
start : func (a * API ) {
37
37
log .Println ("Initializing API on " + a .Host + ":" + a .Port + "..." )
38
38
http .Handle ("/" , a )
@@ -196,20 +196,20 @@ func (a *API) robeaux(res http.ResponseWriter, req *http.Request) {
196
196
// mcp returns MCP route handler.
197
197
// Writes JSON with gobot representation
198
198
func (a * API ) mcp (res http.ResponseWriter , req * http.Request ) {
199
- a .writeJSON (map [string ]interface {}{"MCP" : gobot .NewJSONMaster (a .master )}, res )
199
+ a .writeJSON (map [string ]interface {}{"MCP" : gobot .NewJSONManager (a .manager )}, res )
200
200
}
201
201
202
202
// mcpCommands returns commands route handler.
203
203
// Writes JSON with global commands representation
204
204
func (a * API ) mcpCommands (res http.ResponseWriter , req * http.Request ) {
205
- a .writeJSON (map [string ]interface {}{"commands" : gobot .NewJSONMaster (a .master ).Commands }, res )
205
+ a .writeJSON (map [string ]interface {}{"commands" : gobot .NewJSONManager (a .manager ).Commands }, res )
206
206
}
207
207
208
208
// robots returns route handler.
209
209
// Writes JSON with robots representation
210
210
func (a * API ) robots (res http.ResponseWriter , req * http.Request ) {
211
211
jsonRobots := []* gobot.JSONRobot {}
212
- a .master .Robots ().Each (func (r * gobot.Robot ) {
212
+ a .manager .Robots ().Each (func (r * gobot.Robot ) {
213
213
jsonRobots = append (jsonRobots , gobot .NewJSONRobot (r ))
214
214
})
215
215
a .writeJSON (map [string ]interface {}{"robots" : jsonRobots }, res )
@@ -238,7 +238,7 @@ func (a *API) robotCommands(res http.ResponseWriter, req *http.Request) {
238
238
// robotDevices returns devices route handler.
239
239
// Writes JSON with robot devices representation
240
240
func (a * API ) robotDevices (res http.ResponseWriter , req * http.Request ) {
241
- if robot := a .master .Robot (req .URL .Query ().Get (":robot" )); robot != nil {
241
+ if robot := a .manager .Robot (req .URL .Query ().Get (":robot" )); robot != nil {
242
242
jsonDevices := []* gobot.JSONDevice {}
243
243
robot .Devices ().Each (func (d gobot.Device ) {
244
244
jsonDevices = append (jsonDevices , gobot .NewJSONDevice (d ))
@@ -268,11 +268,11 @@ func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) {
268
268
res .Header ().Set ("Cache-Control" , "no-cache" )
269
269
res .Header ().Set ("Connection" , "keep-alive" )
270
270
271
- device := a .master .Robot (req .URL .Query ().Get (":robot" )).
271
+ device := a .manager .Robot (req .URL .Query ().Get (":robot" )).
272
272
Device (req .URL .Query ().Get (":device" ))
273
273
274
274
//nolint:forcetypeassert // no error return value, so there is no better way
275
- if event := a .master .Robot (req .URL .Query ().Get (":robot" )).
275
+ if event := a .manager .Robot (req .URL .Query ().Get (":robot" )).
276
276
Device (req .URL .Query ().Get (":device" )).(gobot.Eventer ).
277
277
Event (req .URL .Query ().Get (":event" )); len (event ) > 0 {
278
278
//nolint:forcetypeassert // no error return value, so there is no better way
@@ -314,7 +314,7 @@ func (a *API) robotDeviceCommands(res http.ResponseWriter, req *http.Request) {
314
314
// writes JSON with robot connections representation
315
315
func (a * API ) robotConnections (res http.ResponseWriter , req * http.Request ) {
316
316
jsonConnections := []* gobot.JSONConnection {}
317
- if robot := a .master .Robot (req .URL .Query ().Get (":robot" )); robot != nil {
317
+ if robot := a .manager .Robot (req .URL .Query ().Get (":robot" )); robot != nil {
318
318
robot .Connections ().Each (func (c gobot.Connection ) {
319
319
jsonConnections = append (jsonConnections , gobot .NewJSONConnection (c ))
320
320
})
@@ -336,7 +336,7 @@ func (a *API) robotConnection(res http.ResponseWriter, req *http.Request) {
336
336
337
337
// executeMcpCommand calls a global command associated to requested route
338
338
func (a * API ) executeMcpCommand (res http.ResponseWriter , req * http.Request ) {
339
- a .executeCommand (a .master .Command (req .URL .Query ().Get (":command" )),
339
+ a .executeCommand (a .manager .Command (req .URL .Query ().Get (":command" )),
340
340
res ,
341
341
req ,
342
342
)
@@ -350,7 +350,7 @@ func (a *API) executeRobotDeviceCommand(res http.ResponseWriter, req *http.Reque
350
350
} else {
351
351
a .executeCommand (
352
352
//nolint:forcetypeassert // no error return value, so there is no better way
353
- a .master .Robot (req .URL .Query ().Get (":robot" )).
353
+ a .manager .Robot (req .URL .Query ().Get (":robot" )).
354
354
Device (req .URL .Query ().Get (":device" )).(gobot.Commander ).
355
355
Command (req .URL .Query ().Get (":command" )),
356
356
res ,
@@ -365,7 +365,7 @@ func (a *API) executeRobotCommand(res http.ResponseWriter, req *http.Request) {
365
365
a .writeJSON (map [string ]interface {}{"error" : err .Error ()}, res )
366
366
} else {
367
367
a .executeCommand (
368
- a .master .Robot (req .URL .Query ().Get (":robot" )).
368
+ a .manager .Robot (req .URL .Query ().Get (":robot" )).
369
369
Command (req .URL .Query ().Get (":command" )),
370
370
res ,
371
371
req ,
@@ -410,22 +410,22 @@ func (a *API) Debug() {
410
410
}
411
411
412
412
func (a * API ) jsonRobotFor (name string ) (* gobot.JSONRobot , error ) {
413
- if robot := a .master .Robot (name ); robot != nil {
413
+ if robot := a .manager .Robot (name ); robot != nil {
414
414
return gobot .NewJSONRobot (robot ), nil
415
415
}
416
416
return nil , fmt .Errorf ("No Robot found with the name %s" , name )
417
417
}
418
418
419
419
func (a * API ) jsonDeviceFor (robot string , name string ) (* gobot.JSONDevice , error ) {
420
- if device := a .master .Robot (robot ).Device (name ); device != nil {
420
+ if device := a .manager .Robot (robot ).Device (name ); device != nil {
421
421
return gobot .NewJSONDevice (device ), nil
422
422
}
423
423
424
424
return nil , fmt .Errorf ("No Device found with the name %s" , name )
425
425
}
426
426
427
427
func (a * API ) jsonConnectionFor (robot string , name string ) (* gobot.JSONConnection , error ) {
428
- if connection := a .master .Robot (robot ).Connection (name ); connection != nil {
428
+ if connection := a .manager .Robot (robot ).Connection (name ); connection != nil {
429
429
return gobot .NewJSONConnection (connection ), nil
430
430
}
431
431
0 commit comments