MCPcopy
hub / github.com/caddyserver/caddy / MaxSizeSubjectsListForLog

Function MaxSizeSubjectsListForLog

internal/logs.go:9–22  ·  view source on GitHub ↗

MaxSizeSubjectsListForLog returns the keys in the map as a slice of maximum length maxToDisplay. It is useful for logging domains being managed, for example, since a map is typically needed for quick lookup, but a slice is needed for logging, and this can be quite a doozy since there may be a huge a

(subjects map[string]struct{}, maxToDisplay int)

Source from the content-addressed store, hash-verified

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).
9func 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}

Callers 2

CleanupMethod · 0.92
automaticHTTPSPhase2Method · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected