witProtobuf/sampleData.go

60 lines
1.3 KiB
Go

package witProtobuf
import "log"
//
// This generates some sample data. It *should* match the .proto file
//
func CreateSampleEvent() *Event {
// TODO: flush this out to do all the fields
log.Println("CreateSampleEvent() is generating a example protobuf Event")
e := &Event{
Id: 1234,
Name: "Somekind of Event1",
Email: "test+protobuf@wit.com",
Comment: "this is a sample event",
Type: Event_MIGRATE,
Results: []*Event_Response{
{Name: "fooadd", Type: Event_ADD},
{Name: "foodelete", Type: Event_DELETE},
{
Name: "foopoweron",
Type: Event_POWERON,
Error: "No error happened",
Id: 54321,
},
},
}
return e
}
func CreateSampleEvents(total int) []Event {
// TODO: flush this out to do all the fields
log.Println("CreateSampleEvent() is generating %d protobuf Events", total)
var all []Event
for i := 0; i < total; i++ {
e := CreateSampleEvent()
e.Id += 1000 + int32(i)
e.Name = "Sample Event " + string(i)
all = append(all, *e)
}
return all
}
func DumpEventData(myevent *Event) {
log.Println("Received Event name=", myevent)
log.Println("Displaying the Event_Results:")
msgItems := myevent.GetResults()
for _, item := range msgItems {
log.Println("\t", item)
}
}