-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.go
71 lines (56 loc) · 1.52 KB
/
publisher.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Package main provides ...
package main
import (
"github.com/cdn-madness/tweetmap/lib"
"github.com/cdn-madness/tweetmap/protobuf"
"github.com/darkhelmet/twitterstream"
"log"
"time"
)
const CONNSTR string = "tcp://127.0.0.1:7654"
func main() {
// Create a twitterstream tweet
inTweet := new(twitterstream.Tweet)
inTweet.Id = 200976524
inTweet.Coordinates = &twitterstream.Point{
Lat: 11.1,
Long: 11.1,
}
inTweet.User = twitterstream.User{
Id: 987654321,
ScreenName: "alexanderurq",
}
inTweet.Text = "This is a test tweet"
inTweet.Entities.Hashtags = append(inTweet.Entities.Hashtags, twitterstream.Hashtag{
Text: "tweetmap",
})
inTweet.Entities.Media = append(inTweet.Entities.Media, twitterstream.Medium{
MediaUrl: "http://test.com",
})
inTweet.Entities.Mentions = append(inTweet.Entities.Mentions, twitterstream.Mention{
Id: 987654321,
ScreenName: "golang",
})
inTweet.Entities.Urls = append(inTweet.Entities.Urls, twitterstream.Url{
DisplayUrl: "http://test.com",
Url: "http://test.com",
})
// Transform the tweet
var protoTweet = new(prototweet.Tweet)
protoTweet = tweetmap.ToProtoTweet(inTweet)
tweetChan := make(chan *prototweet.Tweet)
errorChan := make(chan error)
tweetmap.InitPublisher(CONNSTR, tweetChan, errorChan)
for i := 0; i < 1000; {
select {
case err := <-errorChan:
log.Println(err.Error())
i = 10
case <-time.After(250 * time.Millisecond):
log.Printf("Sent tweet %s", i)
tweetChan <- protoTweet
i++
}
}
close(tweetChan)
}