-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
45 lines (39 loc) · 1.14 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package drift
import (
"fmt"
"github.com/mayur-tolexo/drift"
)
// new pub created to publish message to nsqd
func ExampleNewPub() {
msg := flag.String("msg", "Hi this is a test", "Message to broadcast")
flag.Parse()
nsqdTCPAddrs := []string{"127.0.0.1:4150"}
d := drift.NewPub(nsqdTCPAddrs)
topic := "elastic"
if resp, err := d.Publish(topic, *msg); err == nil {
fmt.Println(resp)
} else {
fmt.Println(err.Error())
}
}
// This will map a new handeler with specified topic's channel
func ExampleAddChanelHandler() {
d := drift.NewConsumer(nil)
topic := "elastic"
channel := "v6.2"
d.AddChanelHandler(topic, channel, printIT)
}
// This will map a new handeler with all channels of the specified topic.
// If a channelHandler is already mapped with any channel of the specified topic then that handler will be called
// and in rest of the channel this handler will be called.
func ExampleAddTopicHandler() {
d := drift.NewConsumer(nil)
topic := "elastic"
d.AddTopicHandler(topic, printIT)
}
// This will start the drift server to receive request over HTTP
func ExampleStart() {
d := drift.NewConsumer(printIT)
port := 1500
d.Start(port)
}