I have a map that is defined like:
mapMeasures := make(map[time.Time]models.Measure, 0)
with
type Measure struct {
Delta float64 // I just let one field to simplificate
}
So the initial loop will fill values from 22/01/20-10:10:00
to 22/01/20-12:00:00
, so it will store 12 keys value (10 minutes timestep)
Then, it will loop again those timestamp, and add delta to existing value.
So, I need to check if there is already a key corresponding to my actual timestamp:
if val, ok := mapMeasures[ts]; ok { // ts already exists, we must sum delta values
measure.Delta += val.Delta
}
But it appears this condition is never true.
I debugged the code, and I can see the timestamp is actually present inside map:
mapMeasures = {map[time.Time]gitlab.com/company/common/models.Measure}
0 = ->
key = {time.Time} 2020-01-22 11:40:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132460}
1 = ->
key = {time.Time} 2020-01-22 12:30:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132780}
2 = ->
key = {time.Time} 2020-01-22 12:50:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001328c0}
3 = ->
key = {time.Time} 2020-01-22 11:00:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132140}
4 = ->
key = {time.Time} 2020-01-22 11:10:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132280}
5 = ->
key = {time.Time} 2020-01-22 11:20:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132320}
6 = ->
key = {time.Time} 2020-01-22 11:30:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001323c0}
7 = ->
key = {time.Time} 2020-01-22 11:50:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132500}
8 = ->
key = {time.Time} 2020-01-22 12:00:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001325a0}
9 = ->
key = {time.Time} 2020-01-22 12:10:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132640}
10 = ->
key = {time.Time} 2020-01-22 12:20:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc0001326e0}
11 = ->
key = {time.Time} 2020-01-22 12:40:00 +0100
value = {*gitlab.com/company/common/models.Measure | 0xc000132820}
Actual ts
:
{time.Time} 2020-01-22 11:00:00 +0100
Is there any issue with a key to be a timestamp ? Should I convert it to a string, or int ???