forked from cloudfoundry-community/firehose-to-syslog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
44 lines (33 loc) · 996 Bytes
/
main.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
package main
import (
"crypto/tls"
"fmt"
"os"
"github.com/cloudfoundry/noaa"
"github.com/cloudfoundry/noaa/events"
)
var authToken = os.Getenv("CF_ACCESS_TOKEN")
const DopplerAddress = "wss://doppler.10.244.0.34.xip.io:443"
const firehoseSubscriptionId = "firehose-a"
func main() {
connection := noaa.NewConsumer(DopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
connection.SetDebugPrinter(ConsoleDebugPrinter{})
fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")
msgChan := make(chan *events.Envelope)
go func() {
defer close(msgChan)
errorChan := make(chan error)
go connection.Firehose(firehoseSubscriptionId, authToken, msgChan, errorChan, nil)
for err := range errorChan {
fmt.Fprintf(os.Stderr, "%v\n", err.Error())
}
}()
for msg := range msgChan {
fmt.Printf("%v \n", msg)
}
}
type ConsoleDebugPrinter struct{}
func (c ConsoleDebugPrinter) Print(title, dump string) {
println(title)
println(dump)
}