trim values for string lists which can be set as env vars

See #857

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2022-05-31 18:22:18 +02:00
parent 7329cd804b
commit cc2f23bd89
20 changed files with 74 additions and 49 deletions

View File

@@ -66,13 +66,16 @@ func IsStringPrefixInSlice(obj string, list []string) bool {
}
// RemoveDuplicates returns a new slice removing any duplicate element from the initial one
func RemoveDuplicates(obj []string) []string {
func RemoveDuplicates(obj []string, trim bool) []string {
if len(obj) == 0 {
return obj
}
seen := make(map[string]bool)
validIdx := 0
for _, item := range obj {
if trim {
item = strings.TrimSpace(item)
}
if !seen[item] {
seen[item] = true
obj[validIdx] = item
@@ -462,7 +465,7 @@ func HTTPListenAndServe(srv *http.Server, address string, port int, isTLS bool,
func GetTLSCiphersFromNames(cipherNames []string) []uint16 {
var ciphers []uint16
for _, name := range RemoveDuplicates(cipherNames) {
for _, name := range RemoveDuplicates(cipherNames, false) {
for _, c := range tls.CipherSuites() {
if c.Name == strings.TrimSpace(name) {
ciphers = append(ciphers, c.ID)