1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/hello_api_auth.go
deadprogram 953c3254e7 core: use canonical import domain of gobot.io for all code
Signed-off-by: deadprogram <ron@hybridgroup.com>
2016-12-08 13:24:03 +01:00

37 lines
749 B
Go

package main
import (
"fmt"
"html"
"net/http"
"gobot.io/x/gobot"
"gobot.io/x/gobot/api"
)
func main() {
master := gobot.NewMaster()
a := api.NewAPI(master)
a.AddHandler(api.BasicAuth("gort", "klatuu"))
a.Debug()
a.AddHandler(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q \n", html.EscapeString(r.URL.Path))
})
a.Start()
master.AddCommand("custom_gobot_command",
func(params map[string]interface{}) interface{} {
return "This command is attached to the mcp!"
})
hello := master.AddRobot(gobot.NewRobot("hello"))
hello.AddCommand("hi_there", func(params map[string]interface{}) interface{} {
return fmt.Sprintf("This command is attached to the robot %v", hello.Name)
})
master.Start()
}