diff options
Diffstat (limited to 'service_report.go')
| -rw-r--r-- | service_report.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/service_report.go b/service_report.go index 2627bc2..291cd2b 100644 --- a/service_report.go +++ b/service_report.go @@ -3,9 +3,33 @@ package lilin +// historyKeepSize maximum report to keep in history. +const historyKeepSize = 120 + +// historyMax limit of history before its being purged to historyKeepSize. +const historyMax = historyKeepSize * 2 + // ServiceReport contains the scan report for single service. type ServiceReport struct { Name string Last ScanReport History []ScanReport } + +func NewServiceReport(name string) (svcReport *ServiceReport) { + svcReport = &ServiceReport{ + Name: name, + History: make([]ScanReport, 0, historyMax), + } + return svcReport +} + +func (svcReport *ServiceReport) Store(scanReport ScanReport) { + svcReport.Last = scanReport + svcReport.History = append(svcReport.History, scanReport) + if len(svcReport.History) == historyMax { + var start = len(svcReport.History) - historyKeepSize + copy(svcReport.History, svcReport.History[start:]) + svcReport.History = svcReport.History[:historyKeepSize-1] + } +} |
