2014-10-16 01:57:07 +08:00
|
|
|
/*
|
2014-10-29 05:52:59 +08:00
|
|
|
Package api provides a webserver to interact with your Gobot program over the network.
|
2014-10-16 01:57:07 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"github.com/hybridgroup/gobot/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-16 02:02:54 +08:00
|
|
|
gbot := gobot.NewMaster()
|
2014-10-16 01:57:07 +08:00
|
|
|
|
|
|
|
// Starts the API server on default port 3000
|
|
|
|
api.NewAPI(gbot).Start()
|
|
|
|
|
|
|
|
// Accessible via http://localhost:3000/api/commands/say_hello
|
|
|
|
gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
|
|
|
|
return "Master says hello!"
|
|
|
|
})
|
|
|
|
|
|
|
|
hello := gbot.AddRobot(gobot.NewRobot("Eve"))
|
|
|
|
|
|
|
|
// Accessible via http://localhost:3000/robots/Eve/commands/say_hello
|
|
|
|
hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} {
|
|
|
|
return fmt.Sprintf("%v says hello!", hello.Name)
|
|
|
|
})
|
|
|
|
|
|
|
|
gbot.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
It follows Common Protocol for Programming Physical Input and Output (CPPP-IO) spec:
|
|
|
|
https://github.com/hybridgroup/cppp-io
|
|
|
|
*/
|
|
|
|
package api
|