當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。