Skip to content

Commit c159228

Browse files
authored
gobot: rename Master to Manager (hybridgroup#1070)
1 parent 27d0b21 commit c159228

33 files changed

+206
-206
lines changed

CHANGELOG.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@
11831183

11841184
### core
11851185

1186-
* Add Running() methods for Master and Robot and increase test coverage accordingly
1186+
* Add Running() methods for Manager and Robot and increase test coverage accordingly
11871187

11881188
### sysfs
11891189

@@ -1647,17 +1647,17 @@
16471647
### core
16481648

16491649
* Refactoring to allow 'Metal' development using Gobot packages
1650-
* Able to run robots without being part of a Master.
1650+
* Able to run robots without being part of a Manager.
16511651
* Now running all work in separate goroutines
1652-
* Rename internal name of Master type
1652+
* Rename internal name of Manager type
16531653
* Refactor events to use channels all the way down.
16541654
* Eliminate potential race conditions from Events and Every functions
16551655
* Add Unsubscribe() to Eventer, now Once() works as expected
16561656
* DeleteEvent function added to Eventer interface
16571657
* Ranges over event channels instead of using select
16581658
* No longer return non-standard slices of errors, instead use hashicorp/go-multierror
16591659
* Ensure that all drivers have default names
1660-
* Now both Robot and Master operate using AutoRun as expected
1660+
* Now both Robot and Manager operate using AutoRun as expected
16611661
* Use canonical import domain of gobot.io for all code
16621662
* Use time.Sleep unless waiting for a timeout in a select
16631663
* Uses time.NewTimer() instead of time.After() to be more efficient
@@ -2456,7 +2456,7 @@
24562456
* Replaced ginkgo/gomega with system testing package
24572457
* Refactor gobot/robot/device commands
24582458
* Added Event type
2459-
* Replaced Master type with Gobot type
2459+
* Replaced Manager type with Gobot type
24602460
* Every` and `After` now accept `time.Duration`
24612461
* Removed reflection helper methods
24622462

@@ -2580,7 +2580,7 @@
25802580
* Finalize on SIGINT
25812581
* Publish function for driver events
25822582
* device test coverage
2583-
* master and robot test coverage
2583+
* manager and robot test coverage
25842584

25852585
### Clean
25862586

@@ -2600,7 +2600,7 @@
26002600

26012601
### Refactor
26022602

2603-
* robot and master
2603+
* robot and manager
26042604

26052605
### Remove
26062606

@@ -2636,8 +2636,8 @@
26362636
* Travis banner to README
26372637
* api commands
26382638
* POST command
2639-
* master example
2640-
* robot master
2639+
* manager example
2640+
* robot manager
26412641
* Sphero example
26422642
* Digispark to list of supported platforms
26432643
* helper functions
@@ -2737,11 +2737,11 @@
27372737

27382738
### Rename
27392739

2740-
* Gobot struct to Master
2740+
* Gobot struct to Manager
27412741

27422742
### Set
27432743

2744-
* GOMAXPROCS property in GobotMaster
2744+
* GOMAXPROCS property in GobotManager
27452745

27462746
### Skeleton
27472747

README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ func main() {
7878
work := func() {
7979
gobot.Every(1*time.Second, func() {
8080
if err := led.Toggle(); err != nil {
81-
fmt.Println(err)
82-
}
81+
fmt.Println(err)
82+
}
8383
})
8484
}
8585

@@ -90,8 +90,8 @@ func main() {
9090
)
9191

9292
if err := robot.Start(); err != nil {
93-
panic(err)
94-
}
93+
panic(err)
94+
}
9595
}
9696
```
9797

@@ -148,26 +148,26 @@ import (
148148
func main() {
149149
e := edison.NewAdaptor()
150150
if err := e.Connect(); err != nil {
151-
fmt.Println(err)
152-
}
151+
fmt.Println(err)
152+
}
153153

154154
led := gpio.NewLedDriver(e, "13")
155155
if err := led.Start(); err != nil {
156-
fmt.Println(err)
157-
}
156+
fmt.Println(err)
157+
}
158158

159159
for {
160160
if err := led.Toggle(); err != nil {
161-
fmt.Println(err)
162-
}
161+
fmt.Println(err)
162+
}
163163
time.Sleep(1000 * time.Millisecond)
164164
}
165165
}
166166
```
167167

168-
### "Master" Gobot
168+
### "Manager" Gobot
169169

170-
You can also use the full capabilities of the framework aka "Master Gobot" to control swarms of robots or other features
170+
You can also use the full capabilities of the framework aka "Manager Gobot" to control swarms of robots or other features
171171
such as the built-in API server. For example:
172172

173173
```go
@@ -216,8 +216,8 @@ func NewSwarmBot(port string) *gobot.Robot {
216216
}
217217

218218
func main() {
219-
master := gobot.NewMaster()
220-
api.NewAPI(master).Start()
219+
manager := gobot.NewManager()
220+
api.NewAPI(manager).Start()
221221

222222
spheros := []string{
223223
"/dev/rfcomm0",
@@ -227,12 +227,12 @@ func main() {
227227
}
228228

229229
for _, port := range spheros {
230-
master.AddRobot(NewSwarmBot(port))
230+
manager.AddRobot(NewSwarmBot(port))
231231
}
232232

233-
if err := master.Start(); err != nil {
234-
panic(err)
235-
}
233+
if err := manager.Start(); err != nil {
234+
panic(err)
235+
}
236236
}
237237
```
238238

@@ -416,15 +416,15 @@ device status, and execute device commands.
416416
To activate the API, import the `gobot.io/x/gobot/v2/api` package and instantiate the `API` like this:
417417

418418
```go
419-
master := gobot.NewMaster()
420-
api.NewAPI(master).Start()
419+
manager := gobot.NewManager()
420+
api.NewAPI(manager).Start()
421421
```
422422

423423
You can also specify the api host and port, and turn on authentication:
424424

425425
```go
426-
master := gobot.NewMaster()
427-
server := api.NewAPI(master)
426+
manager := gobot.NewManager()
427+
server := api.NewAPI(manager)
428428
server.Port = "4000"
429429
server.AddHandler(api.BasicAuth("gort", "klatuu"))
430430
server.Start()

api/api.go

+18-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// API represents an API server
1919
type API struct {
20-
master *gobot.Master
20+
manager *gobot.Manager
2121
router *pat.PatternServeMux
2222
Host string
2323
Port string
@@ -28,11 +28,11 @@ type API struct {
2828
}
2929

3030
// NewAPI returns a new api instance
31-
func NewAPI(m *gobot.Master) *API {
31+
func NewAPI(m *gobot.Manager) *API {
3232
return &API{
33-
master: m,
34-
router: pat.New(),
35-
Port: "3000",
33+
manager: m,
34+
router: pat.New(),
35+
Port: "3000",
3636
start: func(a *API) {
3737
log.Println("Initializing API on " + a.Host + ":" + a.Port + "...")
3838
http.Handle("/", a)
@@ -196,20 +196,20 @@ func (a *API) robeaux(res http.ResponseWriter, req *http.Request) {
196196
// mcp returns MCP route handler.
197197
// Writes JSON with gobot representation
198198
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)
200200
}
201201

202202
// mcpCommands returns commands route handler.
203203
// Writes JSON with global commands representation
204204
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)
206206
}
207207

208208
// robots returns route handler.
209209
// Writes JSON with robots representation
210210
func (a *API) robots(res http.ResponseWriter, req *http.Request) {
211211
jsonRobots := []*gobot.JSONRobot{}
212-
a.master.Robots().Each(func(r *gobot.Robot) {
212+
a.manager.Robots().Each(func(r *gobot.Robot) {
213213
jsonRobots = append(jsonRobots, gobot.NewJSONRobot(r))
214214
})
215215
a.writeJSON(map[string]interface{}{"robots": jsonRobots}, res)
@@ -238,7 +238,7 @@ func (a *API) robotCommands(res http.ResponseWriter, req *http.Request) {
238238
// robotDevices returns devices route handler.
239239
// Writes JSON with robot devices representation
240240
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 {
242242
jsonDevices := []*gobot.JSONDevice{}
243243
robot.Devices().Each(func(d gobot.Device) {
244244
jsonDevices = append(jsonDevices, gobot.NewJSONDevice(d))
@@ -268,11 +268,11 @@ func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) {
268268
res.Header().Set("Cache-Control", "no-cache")
269269
res.Header().Set("Connection", "keep-alive")
270270

271-
device := a.master.Robot(req.URL.Query().Get(":robot")).
271+
device := a.manager.Robot(req.URL.Query().Get(":robot")).
272272
Device(req.URL.Query().Get(":device"))
273273

274274
//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")).
276276
Device(req.URL.Query().Get(":device")).(gobot.Eventer).
277277
Event(req.URL.Query().Get(":event")); len(event) > 0 {
278278
//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) {
314314
// writes JSON with robot connections representation
315315
func (a *API) robotConnections(res http.ResponseWriter, req *http.Request) {
316316
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 {
318318
robot.Connections().Each(func(c gobot.Connection) {
319319
jsonConnections = append(jsonConnections, gobot.NewJSONConnection(c))
320320
})
@@ -336,7 +336,7 @@ func (a *API) robotConnection(res http.ResponseWriter, req *http.Request) {
336336

337337
// executeMcpCommand calls a global command associated to requested route
338338
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")),
340340
res,
341341
req,
342342
)
@@ -350,7 +350,7 @@ func (a *API) executeRobotDeviceCommand(res http.ResponseWriter, req *http.Reque
350350
} else {
351351
a.executeCommand(
352352
//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")).
354354
Device(req.URL.Query().Get(":device")).(gobot.Commander).
355355
Command(req.URL.Query().Get(":command")),
356356
res,
@@ -365,7 +365,7 @@ func (a *API) executeRobotCommand(res http.ResponseWriter, req *http.Request) {
365365
a.writeJSON(map[string]interface{}{"error": err.Error()}, res)
366366
} else {
367367
a.executeCommand(
368-
a.master.Robot(req.URL.Query().Get(":robot")).
368+
a.manager.Robot(req.URL.Query().Get(":robot")).
369369
Command(req.URL.Query().Get(":command")),
370370
res,
371371
req,
@@ -410,22 +410,22 @@ func (a *API) Debug() {
410410
}
411411

412412
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 {
414414
return gobot.NewJSONRobot(robot), nil
415415
}
416416
return nil, fmt.Errorf("No Robot found with the name %s", name)
417417
}
418418

419419
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 {
421421
return gobot.NewJSONDevice(device), nil
422422
}
423423

424424
return nil, fmt.Errorf("No Device found with the name %s", name)
425425
}
426426

427427
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 {
429429
return gobot.NewJSONConnection(connection), nil
430430
}
431431

api/api_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
func initTestAPI() *API {
2121
log.SetOutput(NullReadWriteCloser{})
22-
g := gobot.NewMaster()
22+
g := gobot.NewManager()
2323
a := NewAPI(g)
2424
a.start = func(m *API) {}
2525
a.Start()
@@ -38,7 +38,7 @@ func initTestAPI() *API {
3838

3939
func TestStartWithoutDefaults(t *testing.T) {
4040
log.SetOutput(NullReadWriteCloser{})
41-
g := gobot.NewMaster()
41+
g := gobot.NewManager()
4242
a := NewAPI(g)
4343
a.start = func(m *API) {}
4444

@@ -396,13 +396,13 @@ func TestRobotDeviceEvent(t *testing.T) {
396396
respc <- resp
397397
}()
398398

399-
event := a.master.Robot("Robot1").
399+
event := a.manager.Robot("Robot1").
400400
Device("Device1").(gobot.Eventer).
401401
Event("TestEvent")
402402

403403
go func() {
404404
time.Sleep(time.Millisecond * 5)
405-
a.master.Robot("Robot1").
405+
a.manager.Robot("Robot1").
406406
Device("Device1").(gobot.Eventer).Publish(event, "event-data")
407407
}()
408408

api/doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Example:
1313
)
1414
1515
func main() {
16-
gbot := gobot.NewMaster()
16+
gbot := gobot.NewManager()
1717
1818
// Starts the API server on default port 3000
1919
api.NewAPI(gbot).Start()
2020
2121
// Accessible via http://localhost:3000/api/commands/say_hello
2222
gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
23-
return "Master says hello!"
23+
return "Manager says hello!"
2424
})
2525
2626
hello := gbot.AddRobot(gobot.NewRobot("Eve"))

0 commit comments

Comments
 (0)