Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | package connection |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // commandMetadata contains metadata about a command sent to the server. |
| 6 | type commandMetadata struct { |
| 7 | Name string |
| 8 | Time time.Time |
| 9 | Legacy bool |
| 10 | FullCollectionName string |
| 11 | } |
| 12 | |
| 13 | // createMetadata creates metadata for a command. |
| 14 | func createMetadata(name string, legacy bool, fullCollName string) *commandMetadata { |
| 15 | return &commandMetadata{ |
| 16 | Name: name, |
| 17 | Time: time.Now(), |
| 18 | Legacy: legacy, |
| 19 | FullCollectionName: fullCollName, |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // TimeDifference returns the difference between now and the time a command was sent in nanoseconds. |
| 24 | func (cm *commandMetadata) TimeDifference() int64 { |
| 25 | t := time.Now() |
| 26 | duration := t.Sub(cm.Time) |
| 27 | return duration.Nanoseconds() |
| 28 | } |