aboutsummaryrefslogtreecommitdiff
path: root/reports.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2025-08-01 02:21:20 +0700
committerShulhan <ms@kilabit.info>2025-08-01 02:21:20 +0700
commit5338799c9fa5158031ebae53c6e64254175e7412 (patch)
tree83ffde1d8bf34e4323c384f0877dfd21090a0ef3 /reports.go
parent5a90a6822fc0d6a0d0d07b4b4583f9dbc20ba0e6 (diff)
downloadlilin-5338799c9fa5158031ebae53c6e64254175e7412.tar.xz
all: record and display the history of failed scan
In the main Reports struct, we record the failed ScanReport in separate slices. Those slices then displayed on the main page under "Fail history" section.
Diffstat (limited to 'reports.go')
-rw-r--r--reports.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/reports.go b/reports.go
index 91ff2df..fdf472e 100644
--- a/reports.go
+++ b/reports.go
@@ -3,8 +3,31 @@
package lilin
+import "sync"
+
+const failKeepSize = 600
+const failMax = failKeepSize + (failKeepSize / 3)
+
// Reports contains the report for all services.
type Reports struct {
Services map[string]*ServiceReport
Title string
+ Fail []ScanReport
+ sync.Mutex
+}
+
+// Store the service scan report.
+func (reports *Reports) Store(scanReport ScanReport) {
+ reports.Lock()
+ var svcReport = reports.Services[scanReport.Name]
+ svcReport.Store(scanReport)
+ if !scanReport.Success {
+ reports.Fail = append(reports.Fail, scanReport)
+ if len(reports.Fail) >= failMax {
+ var start = len(reports.Fail) - failKeepSize
+ copy(reports.Fail, reports.Fail[start:])
+ reports.Fail = reports.Fail[:failKeepSize-1]
+ }
+ }
+ reports.Unlock()
}