-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package report | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Probes contains details of the probe(s) which generated a report. | ||
type Probes map[string]Probe | ||
|
||
// Copy produces a copy of the Probes | ||
func (ps Probes) Copy() Probes { | ||
result := Probes{} | ||
for id, probe := range ps { | ||
result[id] = probe.Copy() | ||
} | ||
return result | ||
} | ||
|
||
// Merge two sets of Probes, keeping the records with the latest LastSeen | ||
func (ps Probes) Merge(other Probes) Probes { | ||
result := ps.Copy() | ||
for id, probe := range other { | ||
o, ok := result[id] | ||
if !ok || o.LastSeen.Before(probe.LastSeen) { | ||
result[id] = probe | ||
} | ||
} | ||
return result | ||
} | ||
|
||
// Probe is the details for a single probe that generated a report. | ||
type Probe struct { | ||
ID string `json:"id"` | ||
LastSeen time.Time `json:"lastSeen"` | ||
} | ||
|
||
// Copy produces a copy of the Probe | ||
func (p Probe) Copy() Probe { | ||
return Probe{ | ||
ID: p.ID, | ||
LastSeen: p.LastSeen, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters