package main import "fmt" import "log" import "net" import "os" import "io" import "bytes" import "github.com/golang/protobuf/proto" import pb "git.wit.com/wit/witProtobuf" var mychannel chan *pb.Event func initChannel() { mychannel = make(chan *pb.Event) } // func processEvents(mychannel chan *pb.Event) { func processEvents() { for { message := <-mychannel log.Println("processEvents() on channel recieved a message = ", message) ReadReceivedData(message) } } func ReadReceivedData(data *pb.Event) { msgItems := data.GetResults() log.Println("ReadReceivedData() Event msgItems=", msgItems) for _, item := range msgItems { log.Println(item) } } func handleProtoClient(conn net.Conn) { fmt.Println("Connected!") defer conn.Close() var buf bytes.Buffer _, err := io.Copy(&buf, conn) if err != nil { fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) return } pdata := pb.CreateSampleEvent() err = proto.Unmarshal(buf.Bytes(), pdata) if err != nil { fmt.Fprintf(os.Stderr, "Fatal error: %s", err.Error()) return } mychannel <- pdata } func addEvent() { msg := pb.CreateSampleEvent() msg.Name = "generated in addEvent()" // var mybuf bytes.Buffer data, err := proto.Marshal(msg) if (err != nil) { log.Printf("something fucked up happened") } pdata := new(pb.Event) // err = proto.Unmarshal(data.Bytes(), pdata) err = proto.Unmarshal(data, pdata) mychannel <- pdata // sendDataToDest(data) // writeBytesToSocket(data) } func sendEventToWIT() { msg := pb.CreateSampleEvent() var mybuf []byte mybuf, err := proto.Marshal(msg) if (err != nil) { log.Printf("something fucked up happened") } writeBytesToSocket(mybuf) }