INNER CODE UNIT · Go
findPolicyFiles
nginx/nginx-gateway-fabric · apis/policygen.go:163
func findPolicyFiles(dir string) ([]string, error) {
entries, err := os.ReadDir(dir)
if err != nil {
return nil, fmt.Errorf("failed to read the %s directory: %w", dir, err)
}
var policyFiles []string
for _, entry := range entries {
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".go") || strings.HasSuffix(entry.Name(), "_test.go") {
continue // filter to use only the `.go` files in directory
}
filePath := filepath.Join(dir, entry.Name())
content, err := os.ReadFile(filePath)
if err != nil {
return nil, fmt.Errorf("failed to read the file %s: %w", filePath, err)
}