GlobPaths expands a list of file patterns into a list of file paths. If no files match a pattern, that pattern will return an error. If no pattern is passed, this returns an empty list and no error. For information on supported glob patterns, see https://pkg.go.dev/path/filepath#Match
(patterns []string)
| 101 | // For information on supported glob patterns, see |
| 102 | // https://pkg.go.dev/path/filepath#Match |
| 103 | func GlobPaths(patterns []string) ([]string, error) { |
| 104 | expansions := []string{} |
| 105 | |
| 106 | for _, pattern := range patterns { |
| 107 | matches, err := filepath.Glob(pattern) |
| 108 | if err != nil { |
| 109 | return nil, fmt.Errorf("%s: %v", pattern, err) |
| 110 | } |
| 111 | if len(matches) == 0 { |
| 112 | return []string{}, fmt.Errorf("no matches found for `%s`", pattern) |
| 113 | } |
| 114 | expansions = append(expansions, matches...) |
| 115 | } |
| 116 | |
| 117 | return expansions, nil |
| 118 | } |