当前位置: 首页>>代码示例>>Golang>>正文


Golang filepath.Match函数代码示例

本文整理汇总了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))
}
开发者ID:hirsch,项目名称:gedd,代码行数:29,代码来源:lookup.go

示例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
}
开发者ID:tiberiuc,项目名称:web-compiler,代码行数:30,代码来源:configvars.go

示例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
}
开发者ID:koolhead17,项目名称:mc,代码行数:29,代码来源:api.go

示例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
}
开发者ID:piranha,项目名称:gostatic,代码行数:28,代码来源:config.go

示例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()")
		}
	}
}
开发者ID:rahulshcse,项目名称:cs733,代码行数:26,代码来源:raft_test.go

示例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
}
开发者ID:tgres,项目名称:tgres,代码行数:31,代码来源:ds_names.go

示例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
	}
}
开发者ID:Rican7,项目名称:sift,代码行数:35,代码来源:gitignore.go

示例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
}
开发者ID:balamurugana,项目名称:mc,代码行数:28,代码来源:client-fs.go

示例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
}
开发者ID:esse-io,项目名称:oil_analysis,代码行数:32,代码来源:main.go

示例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
}
开发者ID:vmware,项目名称:vic,代码行数:34,代码来源:filelist.go

示例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
}
开发者ID:ThinkIntegrate,项目名称:freezer,代码行数:29,代码来源:main.go

示例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
}
开发者ID:kristofer,项目名称:goreplace,代码行数:34,代码来源:ignore.go

示例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
}
开发者ID:esse-io,项目名称:oil_analysis,代码行数:35,代码来源:main.go

示例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
}
开发者ID:tnaoto,项目名称:drone,代码行数:30,代码来源:branch.go

示例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
}
开发者ID:koolhead17,项目名称:mc,代码行数:29,代码来源:share.go


注:本文中的path/filepath.Match函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。