2018-08-16 05:17:57 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
master := gobot.NewMaster()
|
|
|
|
|
|
|
|
a := api.NewAPI(master)
|
2018-08-16 17:22:22 +08:00
|
|
|
|
|
|
|
// creates routes/handlers for the custom API
|
2018-08-16 05:17:57 +08:00
|
|
|
a.Get("/", func(res http.ResponseWriter, req *http.Request) {
|
|
|
|
res.Write([]byte("OK"))
|
|
|
|
})
|
|
|
|
a.Get("/api/hello", func(res http.ResponseWriter, req *http.Request) {
|
|
|
|
msg := fmt.Sprintf("This command is attached to the robot %v", master.Robot("hello").Name)
|
|
|
|
res.Write([]byte(msg))
|
|
|
|
})
|
2018-08-16 17:22:22 +08:00
|
|
|
|
|
|
|
// starts the API without the "standard" C2PIO API or Robeaux web interface.
|
2018-08-16 05:17:57 +08:00
|
|
|
a.StartRaw()
|
|
|
|
|
|
|
|
master.AddRobot(gobot.NewRobot("hello"))
|
|
|
|
|
|
|
|
master.Start()
|
|
|
|
}
|