本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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)
}
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}