Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID() (string, time.Time) cannot match to entity without rounding #2

Open
tvanriper opened this issue Apr 25, 2021 · 0 comments
Open

Comments

@tvanriper
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant