refactor: replace HasPrefix+TrimPrefix with CutPrefix

Signed-off-by: jinjiadu <jinjiadu@aliyun.com>
pull/30909/head
jinjiadu 4 months ago
parent 39305fc160
commit 6f8e9e09a4

@ -170,10 +170,10 @@ func (r *Rules) parseRule(rule string) error {
rule = strings.TrimSuffix(rule, "/")
}
if strings.HasPrefix(rule, "/") {
if after, ok := strings.CutPrefix(rule, "/"); ok {
// Require path matches the root path.
p.match = func(n string, _ os.FileInfo) bool {
rule = strings.TrimPrefix(rule, "/")
rule = after
ok, err := filepath.Match(rule, n)
if err != nil {
slog.Error("failed to compile", "rule", rule, slog.Any("error", err))

Loading…
Cancel
Save