diff --git a/server/datasource/etcd/kv/kv_dao.go b/server/datasource/etcd/kv/kv_dao.go index 93cfc392..da96fa56 100644 --- a/server/datasource/etcd/kv/kv_dao.go +++ b/server/datasource/etcd/kv/kv_dao.go @@ -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 { + value = "(?i)^" + value + } regex, err := regexp.Compile(value) if err != nil { openlog.Error("invalid wildcard expr: " + value + ", error: " + err.Error()) diff --git a/server/datasource/options.go b/server/datasource/options.go index 086dd013..69a9e933 100644 --- a/server/datasource/options.go +++ b/server/datasource/options.go @@ -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 @@ -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) {