go-zero/tools/goctl/model/sql/util/matcher.go

39 lines
624 B
Go
Raw Normal View History

package util
import (
2023-05-06 17:50:54 +08:00
"os"
"path/filepath"
)
// MatchFiles returns the match values by globbing patterns
func MatchFiles(in string) ([]string, error) {
dir, pattern := filepath.Split(in)
abs, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
2023-05-06 17:50:54 +08:00
files, err := os.ReadDir(abs)
if err != nil {
return nil, err
}
var res []string
for _, file := range files {
if file.IsDir() {
continue
}
name := file.Name()
match, err := filepath.Match(pattern, name)
if err != nil {
return nil, err
}
if !match {
continue
}
res = append(res, filepath.Join(abs, name))
}
return res, nil
}