go-zero/tools/goctl/model/sql/util/matcher.go
kingxt e6ef1fca12
Code optimized (#523)
* optimized markdown generator

* optimized markdown generator

* optimized markdown generator

* add more comment

* add comment

* add comment

* add comments for rpc tool

* add comments for model tool

* add comments for model tool

* add comments for model tool

* add comments for config tool

* add comments for config tool

* add comments

* add comments

* add comments

* add comments

* add comment

* remove rpc main head info

* add comment

* optimized

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
2021-02-26 16:11:47 +08:00

39 lines
635 B
Go

package util
import (
"io/ioutil"
"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
}
files, err := ioutil.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
}