INNER CODE UNIT · Go
resolveResourceName
nginx/nginx-gateway-fabric · apis/policygen.go:97
func resolveResourceName(filePath string, allTypes map[string]*ast.StructType) (string, error) {
stem := resourceStemFromFilename(filepath.Base(filePath))
for name := range allTypes {
if strings.ToLower(name) == stem {
return name, nil
}
}
return "", fmt.Errorf("no struct matching filename %q found after expanding the stem: %q)",
filepath.Base(filePath), stem)
}
// targetRefField determines if a policy uses "TargetRef" or
// "TargetRefs". Found is false if neither is present.
func targetRefField(structType *ast.StructType) (singleRef, found bool) {
for _, field := range structType.Fields.List {
for _, name := range field.Names {