1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
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
645 B
Go

package main
import (
"fmt"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/platforms/nats"
)
func main() {
natsAdaptor := nats.NewAdaptorWithAuth("localhost:4222", 1234, "user", "pass")
work := func() {
natsAdaptor.On("hello", func(data []byte) {
fmt.Println("hello")
})
natsAdaptor.On("hola", func(data []byte) {
fmt.Println("hola")
})
data := []byte("o")
gobot.Every(1*time.Second, func() {
natsAdaptor.Publish("hello", data)
})
gobot.Every(5*time.Second, func() {
natsAdaptor.Publish("hola", data)
})
}
robot := gobot.NewRobot("natsBot",
[]gobot.Connection{natsAdaptor},
work,
)
robot.Start()
}