-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
groundwork: ListModels Filtering Upgrade (#2773)
* seperate the filtering from the middleware changes --------- Signed-off-by: Dave Lee <[email protected]>
- Loading branch information
1 parent
f84b55d
commit 307a835
Showing
11 changed files
with
386 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package config | ||
|
||
import "regexp" | ||
|
||
type BackendConfigFilterFn func(string, *BackendConfig) bool | ||
|
||
func NoFilterFn(_ string, _ *BackendConfig) bool { return true } | ||
|
||
func BuildNameFilterFn(filter string) (BackendConfigFilterFn, error) { | ||
if filter == "" { | ||
return NoFilterFn, nil | ||
} | ||
rxp, err := regexp.Compile(filter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return func(name string, config *BackendConfig) bool { | ||
if config != nil { | ||
return rxp.MatchString(config.Name) | ||
} | ||
return rxp.MatchString(name) | ||
}, nil | ||
} | ||
|
||
func BuildUsecaseFilterFn(usecases BackendConfigUsecases) BackendConfigFilterFn { | ||
if usecases == FLAG_ANY { | ||
return NoFilterFn | ||
} | ||
return func(name string, config *BackendConfig) bool { | ||
if config == nil { | ||
return false // TODO: Potentially make this a param, for now, no known usecase to include | ||
} | ||
return config.HasUsecases(usecases) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.