Debian Codegraph @

internal/logs.go

raw symbols SCIP
1 package internal
2
3 import "fmt"
4
5 // MaxSizeSubjectsListForLog returns the keys in the map as a slice of maximum length
6 // maxToDisplay. It is useful for logging domains being managed, for example, since a
7 // map is typically needed for quick lookup, but a slice is needed for logging, and this
8 // can be quite a doozy since there may be a huge amount (hundreds of thousands).
9 func MaxSizeSubjectsListForLog(subjects map[string]struct{}, maxToDisplay int) []string {
10 numberOfNamesToDisplay := min(len(subjects), maxToDisplay)
11 domainsToDisplay := make([]string, 0, numberOfNamesToDisplay)
12 for domain := range subjects {
13 domainsToDisplay = append(domainsToDisplay, domain)
14 if len(domainsToDisplay) >= numberOfNamesToDisplay {
15 break
16 }
17 }
18 if len(subjects) > maxToDisplay {
19 domainsToDisplay = append(domainsToDisplay, fmt.Sprintf("(and %d more...)", len(subjects)-maxToDisplay))
20 }
21 return domainsToDisplay
22 }