Skip to content

Commit

Permalink
provide MatchCase option to match case of keys or not
Browse files Browse the repository at this point in the history
  • Loading branch information
kkf1 committed Aug 30, 2022
1 parent c2eaf67 commit a5a6fa9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion server/datasource/etcd/kv/kv_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,10 @@ func toRegex(opts datasource.FindOptions) (*regexp.Regexp, error) {
default:
value = strings.ReplaceAll(opts.Key, ".", "\\.")
}
value = "(?i)^" + value + "$"
value += "$"
if opts.MatchCase == false {
value = "(?i)^" + value
}
regex, err := regexp.Compile(value)
if err != nil {
openlog.Error("invalid wildcard expr: " + value + ", error: " + err.Error())
Expand Down
10 changes: 9 additions & 1 deletion server/datasource/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ type FindOptions struct {
// Offset the offset of the response, start at 0
Offset int64
// Limit the page size of the response, dot not paging if limit=0
Limit int64
Limit int64
MatchCase bool
}

// WriteOption is functional option to create, update and delete kv
Expand All @@ -86,6 +87,13 @@ func WithSync(enabled bool) WriteOption {
}
}

// WithMatchCase tell model service whether to match case of letters or not.
func WithMatchCase() FindOption {
return func(o *FindOptions) {
o.MatchCase = true
}
}

// WithExactLabels tell model service to return only one kv matches the labels
func WithExactLabels() FindOption {
return func(o *FindOptions) {
Expand Down

0 comments on commit a5a6fa9

Please sign in to comment.