func loadClassificationsFromGolang()

in scripts/update_assets_md/main.go [111:154]


func loadClassificationsFromGolang(filepath string) (*ByProvider, error) {
	output := &ByProvider{
		AWS:   map[string]Classification{},
		Azure: map[string]Classification{},
		GCP:   map[string]Classification{},
	}

	fset := token.NewFileSet()
	node, err := parser.ParseFile(fset, filepath, nil, parser.ParseComments)
	if err != nil {
		return output, fmt.Errorf("failed to parse Go file: %w", err)
	}

	ast.Inspect(node, func(n ast.Node) bool {
		decl, ok := n.(*ast.GenDecl)
		if !ok {
			return true
		}

		for _, spec := range decl.Specs {
			valSpec, ok := spec.(*ast.ValueSpec)
			if !ok {
				continue
			}

			provider, ok := extractProvider(valSpec)
			if !ok {
				continue
			}

			for _, value := range valSpec.Values {
				cl, err := extractClassification(value)
				if err != nil {
					continue
				}
				output.Assign(provider, cl)
			}
		}

		return false
	})

	return output, nil
}