44 "encoding/json"
55 "fmt"
66 "log"
7+ "maps"
78 "os"
89 "sync"
910 "time"
1617 OperatorMetric map [string ]int64
1718 // CTMetrics is a map of operator names to a map of CT log urls to the number of certs processed by said log.
1819 CTMetrics map [string ]OperatorMetric
19- // CTCertIndex is a map of CT log urls to the last processed certficate index on the said log
20+ // CTCertIndex is a map of CT log urls to the last processed certficate index on the said log.
2021 CTCertIndex map [string ]uint64
2122)
2223
@@ -40,13 +41,7 @@ func (m *LogMetrics) GetCTMetrics() CTMetrics {
4041 defer m .mutex .RUnlock ()
4142
4243 copiedMap := make (CTMetrics )
43-
44- for operator , urls := range m .metrics {
45- copiedMap [operator ] = make (OperatorMetric )
46- for url , count := range urls {
47- copiedMap [operator ][url ] = count
48- }
49- }
44+ maps .Copy (copiedMap , m .metrics )
5045
5146 return copiedMap
5247}
@@ -132,20 +127,19 @@ func (m *LogMetrics) Inc(operator, url string, index uint64) {
132127 m .index [url ] = index
133128}
134129
130+ // GetAllCTIndexes returns a copy of the internal CT index map.
135131func (m * LogMetrics ) GetAllCTIndexes () CTCertIndex {
136132 m .mutex .RLock ()
137133 defer m .mutex .RUnlock ()
138134
139- // make a copy of the index and return it
140- // since map is a refrence type
135+ // make a copy of the index and return it, since map is a reference type
141136 copyOfIndex := make (map [string ]uint64 )
142- for k , v := range m .index {
143- copyOfIndex [k ] = v
144- }
137+ maps .Copy (copyOfIndex , m .index )
145138
146139 return copyOfIndex
147140}
148141
142+ // GetCTIndex returns the last cert index processed for a given CT url.
149143func (m * LogMetrics ) GetCTIndex (url string ) uint64 {
150144 m .mutex .RLock ()
151145 defer m .mutex .RUnlock ()
@@ -158,7 +152,7 @@ func (m *LogMetrics) GetCTIndex(url string) uint64 {
158152 return index
159153}
160154
161- // LoadCTIndex loads the last cert index processed for each CT url if it exists
155+ // LoadCTIndex loads the last cert index processed for each CT url if it exists.
162156func (m * LogMetrics ) LoadCTIndex (ctIndexFilePath string ) {
163157 m .mutex .Lock ()
164158 defer m .mutex .Unlock ()
@@ -259,10 +253,12 @@ func (m *LogMetrics) SaveCertIndexes(tempFilePath, ctIndexFilePath string) {
259253 }
260254}
261255
256+ // GetProcessedCerts returns the total number of processed certificates.
262257func GetProcessedCerts () int64 {
263258 return processedCerts
264259}
265260
261+ // GetProcessedPrecerts returns the total number of processed precertificates.
266262func GetProcessedPrecerts () int64 {
267263 return processedPrecerts
268264}
0 commit comments