-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
51 lines (45 loc) · 1008 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package traefiklogger
import (
"io"
"log"
"strings"
)
func containsIgnoreCase(values []string, value string) bool {
for _, str := range values {
if strings.Contains(strings.ToLower(str), strings.ToLower(value)) {
return true
}
}
return false
}
func redact(text string) string {
if len(text) == 0 {
return ""
}
return "██"
}
func decodeEach(value []string, decoder func(string) (string, error)) ([]string, error) {
decodedValues := make([]string, len(value))
for i, v := range value {
decoded, err := decoder(v)
if err == nil {
decodedValues[i] = decoded
} else {
return value, err
}
}
return decodedValues, nil
}
func decodeHeaders(value []string, decoder func(string) string) []string {
decodedValues := make([]string, len(value))
for i, v := range value {
decodedValues[i] = decoder(v)
}
return decodedValues
}
func tryClose(closer io.Closer, logger *log.Logger) {
err := closer.Close()
if err != nil {
logger.Printf("Failed to close: %s", err)
}
}