github.com/kyma-project/kyma/components/asset-store-controller-manager@v0.0.0-20191203152857-3792b5df17c5/internal/path/path.go (about)

     1  package path
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  func Filter(paths []string, filter string) ([]string, error) {
    10  	if filter == "" {
    11  		return paths, nil
    12  	}
    13  
    14  	var filtered []string
    15  	regex, err := regexp.Compile(filter)
    16  	if err != nil {
    17  		return nil, errors.Wrapf(err, "while compiling path filter regex")
    18  	}
    19  	for _, value := range paths {
    20  		if regex.MatchString(value) {
    21  			filtered = append(filtered, value)
    22  		}
    23  	}
    24  	return filtered, nil
    25  }