LoadAllDir load all plugins found beneath the base directory, using the provided error filter to determine whether to fail on individual plugin load errors. This scans only one directory level.
(basedir string, errorFilter ErrorFilterFunc)
| 171 | // |
| 172 | // This scans only one directory level. |
| 173 | func LoadAllDir(basedir string, errorFilter ErrorFilterFunc) ([]Plugin, error) { |
| 174 | // We want <basedir>/*/plugin.yaml |
| 175 | scanpath := filepath.Join(basedir, "*", PluginFileName) |
| 176 | matches, err := filepath.Glob(scanpath) |
| 177 | if err != nil { |
| 178 | return nil, fmt.Errorf("failed to search for plugins in %q: %w", scanpath, err) |
| 179 | } |
| 180 | |
| 181 | plugins := make([]Plugin, 0, len(matches)) |
| 182 | |
| 183 | // empty dir should load |
| 184 | if len(matches) == 0 { |
| 185 | return plugins, nil |
| 186 | } |
| 187 | |
| 188 | for _, yamlFile := range matches { |
| 189 | dir := filepath.Dir(yamlFile) |
| 190 | p, err := LoadDir(dir) |
| 191 | if err != nil { |
| 192 | if errNew := errorFilter(yamlFile, err); errNew != nil { |
| 193 | return plugins, errNew |
| 194 | } |
| 195 | } else { |
| 196 | plugins = append(plugins, p) |
| 197 | } |
| 198 | } |
| 199 | return plugins, detectDuplicates(plugins) |
| 200 | } |
| 201 | |
| 202 | // findFunc is a function that finds plugins in a directory |
| 203 | type findFunc func(pluginsDir string) ([]Plugin, error) |
searching dependent graphs…