func getConfigurations()

in internal/satellite/tools/generate_plugin_doc.go [221:267]


func getConfigurations(category, p reflect.Type) []*pluginConfigurationItem {
	pluginDir := strings.TrimPrefix(p.PkgPath(), GetModuleName())
	fset := token.NewFileSet()

	d, err := parser.ParseDir(fset, "."+pluginDir, nil, parser.ParseComments)
	if err != nil {
		log.Logger.Warnf("failed to generate plugin [%s] configuration, error: %v", category.Name()+"/"+p.Name(), err)
		return make([]*pluginConfigurationItem, 0)
	}

	result := make([]*pluginConfigurationItem, 0)
	for _, f := range d {
		pack := doc.New(f, "./", 0)
		for _, t := range pack.Types {
			if t.Name != p.Name() {
				continue
			}

			for _, spec := range t.Decl.Specs {
				typeSpec, ok := spec.(*ast.TypeSpec)
				if !ok {
					continue
				}
				structType, ok := typeSpec.Type.(*ast.StructType)
				if !ok {
					continue
				}

				for _, field := range structType.Fields.List {
					item, childFinder := parsePluginConfigurationItem(field, p)
					if childFinder != nil {
						configurations := getConfigurations(category, childFinder.childType)
						if childFinder.squash {
							result = append(result, configurations...)
						} else if item != nil {
							item.children = configurations
						}
					}
					if item != nil {
						result = append(result, item)
					}
				}
			}
		}
	}
	return result
}