simdb
simdb copied to clipboard
ID() (string, time.Time) cannot match to entity without rounding
Take a structure like this:
type Session struct {
Start time.Time `json:"start"`
End time.Time `json:"end"`
Client string `json:"client"`
}
and try to devise an 'ID' that refers to "start", say with:
// ID provides a unique identifier for this session
func (s Session) ID() (string, interface{}) {
return "start", s.Start.UnixNano()
}
The records never match.
- time.Time doesn't honor '==', requiring time.Time.Equal(time.Time) to denote equality, so ID() can't return s.Start per the example.
- s.Start.UnixNano() doesn't seem to match, perhaps because there's some randomness.
- s.Start.Unix() works, but requires something like
Session.Start = time.Now().Round(time.Second)to work. - s.Start.Format(time.RFC3339) also works, but requires
Session.Start = time.Now().Round(time.Second)