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


Golang path.Match函数代码示例

本文整理汇总了Golang中path.Match函数的典型用法代码示例。如果您正苦于以下问题:Golang Match函数的具体用法?Golang Match怎么用?Golang Match使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Match函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Match

// Match reports whether ref matches the specified pattern.
// See https://godoc.org/path#Match for supported patterns.
func Match(pattern string, ref Reference) (bool, error) {
	matched, err := path.Match(pattern, ref.String())
	if namedRef, isNamed := ref.(Named); isNamed && !matched {
		matched, _ = path.Match(pattern, namedRef.Name())
	}
	return matched, err
}
开发者ID:docker,项目名称:docker,代码行数:9,代码来源:reference.go

示例2: Glob

// AzureClient -> Glob function
// only supports '*', '?'
// Syntax:
// cntName?/part.*
func (c *AzureClient) Glob(pattern string) (matches []string, err error) {
	afterSplit := strings.Split(pattern, "/")
	cntPattern, blobPattern := afterSplit[0], afterSplit[1]
	if len(afterSplit) != 2 {
		return nil, fmt.Errorf("Glob pattern should follow the Syntax")
	}
	resp, err := c.blobClient.ListContainers(storage.ListContainersParameters{Prefix: ""})
	if err != nil {
		return nil, err
	}
	for _, cnt := range resp.Containers {
		matched, err := path.Match(cntPattern, cnt.Name)
		if err != nil {
			return nil, err
		}
		if !matched {
			continue
		}
		resp, err := c.blobClient.ListBlobs(cnt.Name, storage.ListBlobsParameters{Marker: ""})
		if err != nil {
			return nil, err
		}
		for _, v := range resp.Blobs {
			matched, err := path.Match(blobPattern, v.Name)
			if err != nil {
				return nil, err
			}
			if matched {
				matches = append(matches, cnt.Name+"/"+v.Name)
			}
		}
	}
	return matches, nil
}
开发者ID:yangjunpro,项目名称:taskgraph,代码行数:38,代码来源:azure.go

示例3: getMiddlewares

func (e *Emitter) getMiddlewares(topic string) []func(*Event) {
	var acc []func(*Event)
	for pattern, v := range e.middlewares {
		if match, _ := path.Match(pattern, topic); match {
			acc = append(acc, v...)
		} else if match, _ := path.Match(topic, pattern); match {
			acc = append(acc, v...)
		}
	}
	return acc
}
开发者ID:olebedev,项目名称:emitter,代码行数:11,代码来源:emitter.go

示例4: MatchTarget

// MatchTarget returns true if t's name or outputs match pattern.
func MatchTarget(pattern string, t *Target) (matched bool, err error) {
	if matched, err = path.Match(pattern, t.Name); matched || err != nil {
		return
	}

	for _, output := range t.Outputs {
		if matched, err = path.Match(pattern, output); matched || err != nil {
			return
		}
	}

	return
}
开发者ID:benbjohnson,项目名称:bake,代码行数:14,代码来源:bake.go

示例5: SendLog

func SendLog(url, dir string, upload, keep time.Duration) error {
	err := filepath.Walk(dir, func(filename string, f os.FileInfo, err error) error {
		if f == nil {
			info_err := errors.New("Filepath.Walk() returned no fileinfo")
			glog.Errorf("%v", info_err)
			return nil
		}
		if f.IsDir() {
			return nil
		}
		if b, _ := path.Match("LOG.*.*????-??-??T??:??:??Z", f.Name()); b {
			fields := strings.Split(f.Name(), ".")
			t, _ := time.Parse("MST2006-01-02T15:04:05Z", fields[2])
			time_int := t.Unix()
			// glog.Infoln("Log created at: ", t, "\tTime now: ", time.Now())
			// fmt.Println("Log created at: ", t, "\tTime now: ", time.Now())
			if time.Now().Unix()-int64(upload.Seconds()) > time_int {
				post_err := PostFile(filename, url)
				if post_err != nil {
					// glog.Errorf("Upload file failed, %v", post_err)
				} else {
					os.Rename(filename, path.Dir(filename)+"/OLD."+f.Name())
					glog.Infof("%s upload succeed \n", filename)
					fmt.Printf("%s upload succeed \n", filename)
				}
			}
			return nil
		}
		if b, _ := path.Match("OLD.LOG.*.*????-??-??T??:??:??Z", f.Name()); b {
			fields := strings.Split(f.Name(), ".")
			t, _ := time.Parse("MST2006-01-02T15:04:05Z", fields[3])
			time_int := t.Unix()
			if time.Now().Unix()-int64(keep.Seconds()) > time_int {
				err := os.Remove(filename)
				if err == nil {
					glog.Infof("%s removed \n", filename)
					fmt.Printf("%s removed \n", filename)
				}
			}
			return nil
		}
		return nil
	})
	if err != nil {
		return err
	}
	return nil
}
开发者ID:deepglint,项目名称:logmanager,代码行数:48,代码来源:client.go

示例6: watcherLoop

func watcherLoop(watcher *fsnotify.Watcher) {
	var cmd *exec.Cmd
	for {
		select {
		case event := <-watcher.Events:
			if event.Op&fsnotify.Write == fsnotify.Write {
				for i := range tasks {
					p := "./" + tasks[i].Pattern
					if m, err := path.Match(p, event.Name); m && (err == nil) {
						if cmd != nil {
							cmd.Process.Kill()
						}
						name := tasks[i].Command[0]
						args := tasks[i].Command[1:]
						log.Print("> ", tasks[i].Name)
						cmd = exec.Command(name, args...)
						cmd.Stdout = os.Stdout
						cmd.Stderr = os.Stderr
						cmd.Start()
					}
				}
			}
		case err := <-watcher.Errors:
			log.Println("error:", err)
		}
	}
}
开发者ID:the-varlog,项目名称:godience,代码行数:27,代码来源:godience.go

示例7: Find

// Find returns the cleaned path of every file in the supplied zip reader whose
// base name matches the supplied pattern, which is interpreted as in path.Match.
func Find(reader *zip.Reader, pattern string) ([]string, error) {
	// path.Match will only return an error if the pattern is not
	// valid (*and* the supplied name is not empty, hence "check").
	if _, err := path.Match(pattern, "check"); err != nil {
		return nil, err
	}
	var matches []string
	for _, zipFile := range reader.File {
		cleanPath := path.Clean(zipFile.Name)
		baseName := path.Base(cleanPath)
		if match, _ := path.Match(pattern, baseName); match {
			matches = append(matches, cleanPath)
		}
	}
	return matches, nil
}
开发者ID:jameinel,项目名称:core,代码行数:18,代码来源:zip.go

示例8: subtreeMatch

func (r *URIPathResolver) subtreeMatch(c cookoo.Context, pathName, pattern string) bool {

	if pattern == "**" {
		return true
	}

	// Find out how many slashes we have.
	countSlash := strings.Count(pattern, "/")

	// '**' matches anything.
	if countSlash == 0 {
		c.Logf("warn", "Illegal pattern: %s", pattern)
		return false
	}

	// Add 2 for verb plus trailer.
	parts := strings.SplitN(pathName, "/", countSlash+1)
	prefix := strings.Join(parts[0:countSlash], "/")

	subpattern := strings.Replace(pattern, "/**", "", -1)
	if ok, err := path.Match(subpattern, prefix); ok && err == nil {
		return true
	} else if err != nil {
		c.Logf("warn", "Parsing path `%s` gave error: %s", err)
	}
	return false
}
开发者ID:ngpestelos,项目名称:deis,代码行数:27,代码来源:uripathresolver.go

示例9: main

func main() {
	var cDir, _ = os.Getwd()
	cDir += "/"

	var _, filePattern = path.Split(cDir)

	fileInfos, err := ioutil.ReadDir(cDir)
	if err != nil {
		log.Fatal(err)
	}

	sort.Sort(byName(fileInfos))
	for _, fileInfo := range fileInfos {
		var findName = (fileInfo).Name()
		var findTime = (fileInfo).ModTime().Unix()

		var matched = true
		if filePattern != "" {
			matched, _ = path.Match(filePattern, findName)
		}
		if matched == true {
			fmt.Printf("%s\n", findName)
			fmt.Println(findTime)
		}
	}
}
开发者ID:zchee,项目名称:go-sandbox,代码行数:26,代码来源:sorting_fileinfo.go

示例10: getFiles

// getFiles returns a sorted list of files in the directory
// in which fname exists starting with fname (i.e. fname*).
func getFiles(fname string) ([]string, error) {
	dn := path.Dir(fname)
	bn := path.Base(fname)
	files, err := ioutil.ReadDir(dn)
	if err != nil {
		return nil, err
	}
	match := make([]os.FileInfo, len(files))
	count := 0
	for _, f := range files {
		if m, _ := path.Match(bn+".*", f.Name()); m {
			match[count] = f
			count++
		}
	}
	if count > 0 {
		res := make([]string, count)
		for i, f := range match[:count] {
			res[i] = fmt.Sprintf("%s/%s", dn, f.Name())
		}
		sort.Sort(handysort.Strings(res))
		return res, nil
	}
	return nil, nil
}
开发者ID:teenooCH,项目名称:llog,代码行数:27,代码来源:LevelLogger.go

示例11: Drop

func Drop(item interface{}, items []interface{}) ([]interface{}, error) {
	var out []interface{}
	pattern, isstr := item.(string)
	if isstr {
		for i := range items {
			str, ok := items[i].(string)
			if !ok {
				return nil, fmt.Errorf("all elements must be a string to drop a string")
			}
			match, err := path.Match(pattern, str)
			if err != nil {
				return nil, fmt.Errorf("bad pattern: %s", pattern)
			}
			if !match {
				out = append(out, items[i])
			}
		}
		return out, nil
	}
	for i := range items {
		if item != items[i] {
			out = append(out, items[i])
		}
	}
	return out, nil
}
开发者ID:pombredanne,项目名称:sigil,代码行数:26,代码来源:builtin.go

示例12: parseFilter

func parseFilter(envname string, pad func(string) string) map[string]bool {
	filter := make(map[string]bool)

	env := os.Getenv(envname)
	if env == "" {
		return filter
	}

	for _, fn := range strings.Split(env, ",") {
		t := pad(strings.TrimSpace(fn))
		val := true
		if t[0] == '-' {
			val = false
			t = t[1:]
		} else if t[0] == '+' {
			val = true
			t = t[1:]
		}

		// test pattern
		_, err := path.Match(t, "")
		if err != nil {
			fmt.Fprintf(os.Stderr, "error: invalid pattern %q: %v\n", t, err)
			os.Exit(5)
		}

		filter[t] = val
	}

	return filter
}
开发者ID:ckemper67,项目名称:restic,代码行数:31,代码来源:debug.go

示例13: findImages

func findImages(cfg *config.CloudConfig) ([]string, error) {
	log.Debugf("Looking for images at %s", config.IMAGES_PATH)

	result := []string{}

	dir, err := os.Open(config.IMAGES_PATH)
	if os.IsNotExist(err) {
		log.Debugf("Not loading images, %s does not exist")
		return result, nil
	}
	if err != nil {
		return nil, err
	}

	defer dir.Close()

	files, err := dir.Readdirnames(0)
	if err != nil {
		return nil, err
	}

	for _, fileName := range files {
		if ok, _ := path.Match(config.IMAGES_PATTERN, fileName); ok {
			log.Debugf("Found %s", fileName)
			result = append(result, fileName)
		}
	}

	return result, nil
}
开发者ID:rowhit,项目名称:os,代码行数:30,代码来源:sysinit.go

示例14: globMatches

func globMatches(pattern, target string) bool {
	matched, err := path.Match(pattern, target)
	if err != nil {
		log.V(2).Infof("Received error while matching pattern '%s': %v", pattern, err)
	}
	return matched
}
开发者ID:natacado,项目名称:fleet,代码行数:7,代码来源:state.go

示例15: Match

func (self *attachedFilter) Match(event string) (ok bool) {
	var err error
	if ok, err = path.Match(self.Pattern, event); err != nil {
		panic(err.Error())
	}
	return
}
开发者ID:nu7hatch,项目名称:gosewer,代码行数:7,代码来源:filter.go


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