本文整理汇总了Golang中path/filepath.Match函数的典型用法代码示例。如果您正苦于以下问题:Golang Match函数的具体用法?Golang Match怎么用?Golang Match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lookup
// lookup prints all filenames matching the pattern
func lookup(data []*DirEntry, query string) {
query = strings.ToLower(query)
elapsedTime := time.Now()
results := 0
checked := 0
for _, dir := range data {
match, err := filepath.Match(query, strings.ToLower(filepath.Base(dir.Path)))
fatal(err)
if match {
fmt.Println(blue + dir.Path + string(filepath.Separator) + reset)
results++
}
checked++
for _, file := range dir.Files {
match, err := filepath.Match(query, strings.ToLower(file.Name))
fatal(err)
if match {
fmt.Println(filepath.Join(dir.Path, red+file.Name+reset))
results++
}
checked++
}
}
fmt.Println("Results:", results, "/", checked, "Time:", time.Since(elapsedTime))
}
示例2: ProcessData
func (p *Configvars) ProcessData(src []byte, relPath string, fileName string) ([]byte, error) {
shouldProcess := true
if len(p.include) > 0 {
shouldProcess = false
for _, match := range p.include {
if matched, _ := filepath.Match(match, fileName); matched {
shouldProcess = true
break
}
}
} else {
for _, match := range p.exclude {
if matched, _ := filepath.Match(match, fileName); matched {
shouldProcess = false
break
}
}
}
if shouldProcess {
data := string(src)
for name, value := range p.vars {
data = strings.Replace(data, "{{"+name+"}}", value, -1)
}
return []byte(data), nil
}
return src, nil
}
示例3: New
// New - instantiate minio client API with your input Config{}.
func New(config Config) (CloudStorageAPI, error) {
if strings.TrimSpace(config.Region) == "" || len(config.Region) == 0 {
u, err := url.Parse(config.Endpoint)
if err != nil {
return API{}, err
}
match, _ := filepath.Match("*.s3*.amazonaws.com", u.Host)
if match {
config.isVirtualStyle = true
hostSplits := strings.SplitN(u.Host, ".", 2)
u.Host = hostSplits[1]
}
matchGoogle, _ := filepath.Match("*.storage.googleapis.com", u.Host)
if matchGoogle {
config.isVirtualStyle = true
hostSplits := strings.SplitN(u.Host, ".", 2)
u.Host = hostSplits[1]
}
config.Region = getRegion(u.Host)
if config.Region == "google" {
// Google cloud storage is signature V2
config.Signature = SignatureV2
}
}
config.SetUserAgent(LibraryName, LibraryVersion, runtime.GOOS, runtime.GOARCH)
config.isUserAgentSet = false // default
return API{apiCore{&config}}, nil
}
示例4: MatchedRule
func (rules RuleMap) MatchedRule(path string) (string, *Rule) {
if rules[path] != nil {
return path, rules[path]
}
_, name := filepath.Split(path)
if rules[name] != nil {
return name, rules[name]
}
for pat, rule := range rules {
matched, err := filepath.Match(pat, path)
errhandle(err)
if matched {
return pat, rule
}
}
for pat, rule := range rules {
matched, err := filepath.Match(pat, name)
errhandle(err)
if matched {
return pat, rule
}
}
return "", nil
}
示例5: deleteOldLogs
func deleteOldLogs() {
dirname := "." + string(filepath.Separator)
d, err := os.Open(dirname)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer d.Close()
files, err := d.Readdir(-1)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
for _, file := range files {
if boolvar, err := filepath.Match("log*", file.Name()); err == nil && boolvar == true {
os.Remove("file.Name()")
} else if boolvar, err := filepath.Match("statelog*", file.Name()); err == nil && boolvar == true {
os.Remove("file.Name()")
} else if boolvar, err := filepath.Match("testlog*", file.Name()); err == nil && boolvar == true {
os.Remove("file.Name()")
}
}
}
示例6: fsFind
func (dsns *DataSourceNames) fsFind(pattern string) []*FsFindNode {
dsns.RLock()
defer dsns.RUnlock()
dots := strings.Count(pattern, ".")
set := make(map[string]*FsFindNode)
for k, dsId := range dsns.names {
if yes, _ := filepath.Match(pattern, k); yes && dots == strings.Count(k, ".") {
set[k] = &FsFindNode{Name: k, Leaf: true, dsId: dsId}
}
}
for k, _ := range dsns.prefixes {
if yes, _ := filepath.Match(pattern, k); yes && dots == strings.Count(k, ".") {
set[k] = &FsFindNode{Name: k, Leaf: false}
}
}
// convert to array
result := make(fsNodes, 0)
for _, v := range set {
result = append(result, v)
}
// so that results are consistently ordered, or Grafanas get confused
sort.Sort(result)
return result
}
示例7: Matches
func (p pathPattern) Matches(path string, fi os.FileInfo) bool {
if p.matchDirOnly && !fi.IsDir() {
return false
}
if runtime.GOOS == "windows" {
path = filepath.ToSlash(path)
}
if p.leadingSlash {
res, err := filepath.Match(p.content, path)
if err != nil {
return false
}
return res
} else {
slashes := 0
pos := 0
for pos = len(path) - 1; pos >= 0; pos-- {
if path[pos:pos+1] == "/" {
slashes++
if slashes > p.depth {
break
}
}
}
if slashes < p.depth {
return false
}
checkpath := path[pos+1:]
res, err := filepath.Match(p.content, checkpath)
if err != nil {
return false
}
return res
}
}
示例8: isIgnoredFile
// isIgnoredFile returns true if 'filename' is on the exclude list.
func isIgnoredFile(filename string) bool {
matchFile := path.Base(filename)
// OS specific ignore list.
for _, ignoredFile := range ignoreFiles[runtime.GOOS] {
matched, err := filepath.Match(ignoredFile, matchFile)
if err != nil {
panic(err)
}
if matched {
return true
}
}
// Default ignore list for all OSes.
for _, ignoredFile := range ignoreFiles["default"] {
matched, err := filepath.Match(ignoredFile, matchFile)
if err != nil {
panic(err)
}
if matched {
return true
}
}
return false
}
示例9: listFiles
func listFiles(path string, f os.FileInfo, err error) error {
if f == nil {
return err
}
if f.IsDir() {
return nil
}
matched, _ := filepath.Match("disposition*.csv", filepath.Base(path))
if matched {
e := handleDisposition(*output_path, path)
if e != nil {
fmt.Println("failed to deal with ", path)
}
}
matched, _ = filepath.Match("lease*.csv", filepath.Base(path))
if matched {
e := handleLease(*output_path, path)
if e != nil {
fmt.Println("failed to deal with ", path)
}
}
matched, _ = filepath.Match("production*.csv", filepath.Base(path))
if matched {
e := handleProduction(*output_path, path)
if e != nil {
fmt.Println("failed to deal with ", path)
}
}
return nil
}
示例10: Contains
func (f *filelist) Contains(pathname string) bool {
// Ignore dot files
_, filename := filepath.Split(pathname)
if strings.HasPrefix(filename, ".") {
return true
}
cwd, _ := os.Getwd()
abs, _ := filepath.Abs(pathname)
for _, pattern := range *f {
// Also check working directory
rel := path.Join(cwd, pattern)
// Match pattern directly
if matched, _ := filepath.Match(pattern, pathname); matched {
return true
}
// Also check pattern relative to working directory
if matched, _ := filepath.Match(rel, pathname); matched {
return true
}
// Finally try absolute path
st, e := os.Stat(rel)
if os.IsExist(e) && st.IsDir() && strings.HasPrefix(abs, rel) {
return true
}
}
return false
}
示例11: shouldAnalyse
func shouldAnalyse(p string) (b bool) {
for e := IgnoredFiles.Front(); e != nil; e = e.Next() {
pattern, ok := e.Value.(string)
if strings.HasSuffix(pattern, "/") && (strings.Index(pattern, "*") < 0) {
if strings.HasPrefix(p, pattern) {
return false
}
} else {
if !ok {
return false
}
matched, error := filepath.Match(pattern, p)
//fmt.Println(pattern+": "+p)
//fmt.Println(matched)
if error != nil {
return false
}
if matched {
return false
}
_, file := filepath.Split(p)
matched, error = filepath.Match(file, p)
if matched {
return false
}
}
}
return true
}
示例12: Ignore
func (i *GitIgnorer) Ignore(fn string, isdir bool) bool {
fullpath := filepath.Join(i.basepath, i.prefix, fn)
prefpath := filepath.Join(i.prefix, fn)
base := filepath.Base(prefpath)
dirpath := prefpath[:len(prefpath)-len(base)]
if isdir && base == ".git" {
return true
}
for _, pat := range i.globs {
if strings.Index(pat, "/") != -1 {
if m, _ := filepath.Match(pat, fullpath); m {
return true
}
} else if m, _ := filepath.Match(pat, fn); m {
return true
}
}
for _, pat := range i.res {
if pat.Match([]byte(fn)) {
return true
}
}
for _, dir := range i.dirs {
if strings.Contains(dirpath, dir) {
return true
}
}
return false
}
示例13: loadDispoFiles
func loadDispoFiles(path string, f os.FileInfo, err error) error {
if f == nil {
return err
}
if f.IsDir() {
return nil
}
file, err := os.Open(path)
if err != nil {
fmt.Printf("failed to open file %s", path)
return nil
}
defer file.Close()
matched, _ := filepath.Match("disposition*.gas.json", filepath.Base(path))
if matched {
var detail []DisposGas
jsonParser := json.NewDecoder(file)
if err = jsonParser.Decode(&detail); err != nil {
fmt.Printf("Fail to parsing file %s : %s", f.Name, err.Error())
} else {
disposGasDetail = append(disposGasDetail, detail...)
}
}
matched, _ = filepath.Match("disposition*.oil.json", filepath.Base(path))
if matched {
var detail []DisposOil
jsonParser := json.NewDecoder(file)
if err = jsonParser.Decode(&detail); err != nil {
fmt.Printf("Fail to parsing file %s : %s", f.Name, err.Error())
} else {
disposOilDetail = append(disposOilDetail, detail...)
}
}
return nil
}
示例14: Matches
// Matches returns true if the branch matches the include patterns and
// does not match any of the exclude patterns.
func (b *Branch) Matches(branch string) bool {
// when no includes or excludes automatically match
if len(b.Include) == 0 && len(b.Exclude) == 0 {
return true
}
// exclusions are processed first. So we can include everything and
// then selectively exclude certain sub-patterns.
for _, pattern := range b.Exclude {
if pattern == branch {
return false
}
if ok, _ := filepath.Match(pattern, branch); ok {
return false
}
}
for _, pattern := range b.Include {
if pattern == branch {
return true
}
if ok, _ := filepath.Match(pattern, branch); ok {
return true
}
}
return false
}
示例15: isObjectKeyPresent
// this code is necessary since, share only operates on cloud storage URLs not filesystem
func isObjectKeyPresent(url string) bool {
u := client.NewURL(url)
path := u.Path
matchS3, _ := filepath.Match("*.s3*.amazonaws.com", u.Host)
if matchS3 {
hostSplits := strings.SplitN(u.Host, ".", 2)
path = string(u.Separator) + hostSplits[0] + u.Path
}
matchGcs, _ := filepath.Match("*.storage.googleapis.com", u.Host)
if matchGcs {
hostSplits := strings.SplitN(u.Host, ".", 2)
path = string(u.Separator) + hostSplits[0] + u.Path
}
pathSplits := strings.SplitN(path, "?", 2)
splits := strings.SplitN(pathSplits[0], string(u.Separator), 3)
switch len(splits) {
case 0, 1:
return false
case 2:
return false
case 3:
if splits[2] == "" {
return false
}
return true
}
return false
}