package main import ( "fmt" "sync" ) type ChannelItem struct { tag string upBytes uint64 downBytes uint64 } type DurationChannelItems struct { durationTag string channelItemMap map[string]*ChannelItem } var durationChannelItemsMap = map[string]DurationChannelItems{} var durationChannelItemsMapLock = sync.RWMutex{} type CountItem struct { tag string timestamp uint64 upBytes uint64 downBytes uint64 } func (i *CountItem) merge(i2 *CountItem) (*CountItem, error) { if i.tag != i2.tag { return nil, fmt.Errorf("Tag mis match %s vs %s", i.tag, i2.tag) } t1 := uint64(i.timestamp/1000) * 1000 t2 := uint64(i2.timestamp/1000) * 1000 if t1 != t2 { return nil, fmt.Errorf("Timestamp mis match %d vs %d", t1, t2) } i3 := &CountItem{ tag: i.tag, timestamp: t1, upBytes: i.upBytes + i2.upBytes, downBytes: i.downBytes + i2.downBytes, } return i3, nil } var countItemChan = make(chan CountItem) // var countItemChan = make(ChannelItem, 0) func main() { } func collectCountItem() { for { countItem := <-countItemChan // TODO ... fmt.Printf("%v\n", countItem) } } func makeDurationTag(timestamp uint64) string { return fmt.Sprintf("%d", uint64(timestamp/1000)) }