2013-11-28 12:05:45 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-22 13:19:04 +08:00
|
|
|
"html"
|
|
|
|
"net/http"
|
2014-07-11 08:21:21 +08:00
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/api"
|
2013-11-28 12:05:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2016-10-19 03:08:25 +08:00
|
|
|
master := gobot.NewMaster()
|
2013-11-28 12:05:45 +08:00
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
a := api.NewAPI(master)
|
2014-07-22 13:19:04 +08:00
|
|
|
a.AddHandler(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintf(w, "Hello, %q \n", html.EscapeString(r.URL.Path))
|
2014-06-13 11:58:54 +08:00
|
|
|
})
|
2014-09-19 11:12:49 +08:00
|
|
|
a.Debug()
|
2014-07-22 13:19:04 +08:00
|
|
|
a.Start()
|
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.AddCommand("custom_gobot_command",
|
2014-07-22 13:19:04 +08:00
|
|
|
func(params map[string]interface{}) interface{} {
|
|
|
|
return "This command is attached to the mcp!"
|
|
|
|
})
|
2014-06-12 07:44:23 +08:00
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
hello := master.AddRobot(gobot.NewRobot("hello"))
|
2014-07-09 09:36:14 +08:00
|
|
|
|
|
|
|
hello.AddCommand("hi_there", func(params map[string]interface{}) interface{} {
|
2014-07-11 10:28:00 +08:00
|
|
|
return fmt.Sprintf("This command is attached to the robot %v", hello.Name)
|
2014-06-12 07:44:23 +08:00
|
|
|
})
|
2013-11-28 12:05:45 +08:00
|
|
|
|
2016-10-19 03:08:25 +08:00
|
|
|
master.Start()
|
2013-11-28 12:05:45 +08:00
|
|
|
}
|