Skip to content

Commit

Permalink
enhance: Trim space during parsing string list from string (milvus-io…
Browse files Browse the repository at this point in the history
…#35546)

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 authored Aug 19, 2024
1 parent 227ecd3 commit 853d2f3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"

"github.com/cockroachdb/errors"
"github.com/samber/lo"

"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
Expand Down Expand Up @@ -286,7 +287,7 @@ func DatabaseLevelResourceGroups(kvs []*commonpb.KeyValuePair) ([]string, error)
return nil, invalidPropValue
}

return rgs, nil
return lo.Map(rgs, func(rg string, _ int) string { return strings.TrimSpace(rg) }), nil
}
}

Expand Down Expand Up @@ -321,7 +322,7 @@ func CollectionLevelResourceGroups(kvs []*commonpb.KeyValuePair) ([]string, erro
return nil, invalidPropValue
}

return rgs, nil
return lo.Map(rgs, func(rg string, _ int) string { return strings.TrimSpace(rg) }), nil
}
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/util/paramtable/param_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

"github.com/samber/lo"
"go.uber.org/atomic"

"github.com/milvus-io/milvus/pkg/config"
Expand Down Expand Up @@ -335,7 +336,8 @@ func getAsStrings(v string) []string {
return []string{}
}
return getAndConvert(v, func(value string) ([]string, error) {
return strings.Split(value, ","), nil
ret := strings.Split(value, ",")
return lo.Map(ret, func(rg string, _ int) string { return strings.TrimSpace(rg) }), nil
}, []string{})
}

Expand Down

0 comments on commit 853d2f3

Please sign in to comment.