updated to use the sample generated events

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-11 12:45:17 -07:00
parent 0067c55003
commit b49aed2de0
1 changed files with 9 additions and 16 deletions

View File

@ -8,7 +8,7 @@ import "io"
import "bytes" import "bytes"
import "github.com/golang/protobuf/proto" import "github.com/golang/protobuf/proto"
import pb "git.wit.com/jcarr/witProtobuf" import pb "git.wit.com/wit/witProtobuf"
var mychannel chan *pb.Event var mychannel chan *pb.Event
@ -20,16 +20,16 @@ func initChannel() {
func processEvents() { func processEvents() {
for { for {
message := <-mychannel message := <-mychannel
log.Println("processEvents() on channel recieved a message") log.Println("processEvents() on channel recieved a message = ", message)
ReadReceivedData(message) ReadReceivedData(message)
} }
} }
func ReadReceivedData(data *pb.Event) { func ReadReceivedData(data *pb.Event) {
msgItems := data.GetResults() msgItems := data.GetResults()
fmt.Println("Receiving data...") log.Println("ReadReceivedData() Event msgItems=", msgItems)
for _, item := range msgItems { for _, item := range msgItems {
fmt.Println(item) log.Println(item)
} }
} }
@ -42,7 +42,7 @@ func handleProtoClient(conn net.Conn) {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
return return
} }
pdata := new(pb.Event) pdata := pb.CreateSampleEvent()
err = proto.Unmarshal(buf.Bytes(), pdata) err = proto.Unmarshal(buf.Bytes(), pdata)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error())
@ -52,8 +52,8 @@ func handleProtoClient(conn net.Conn) {
} }
func addEvent() { func addEvent() {
msg := new(pb.Event) msg := pb.CreateSampleEvent()
msg.Name = "hello jeff" msg.Name = "generated in addEvent()"
// var mybuf bytes.Buffer // var mybuf bytes.Buffer
@ -69,17 +69,10 @@ func addEvent() {
// writeBytesToSocket(data) // writeBytesToSocket(data)
} }
func createProtobufEvent() *pb.Event {
msg := new(pb.Event)
msg.Name = "hello jeff"
return msg
}
func sendEventToWIT() { func sendEventToWIT() {
msg := createProtobufEvent() msg := pb.CreateSampleEvent()
var mybuf []byte
var mybuf []byte
mybuf, err := proto.Marshal(msg) mybuf, err := proto.Marshal(msg)
if (err != nil) { if (err != nil) {
log.Printf("something fucked up happened") log.Printf("something fucked up happened")