Skip to content

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

Description

@tvanriper

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions