MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / WithPlugins

Function WithPlugins

internal/cnpi/plugin/client/client.go:79–108  ·  view source on GitHub ↗

WithPlugins creates a new CNPG-I client for plugins in a certain repository, loading the plugins with the specified name

(ctx context.Context, repository repository.Interface, names ...string)

Source from the content-addressed store, hash-verified

77// WithPlugins creates a new CNPG-I client for plugins in a certain repository,
78// loading the plugins with the specified name
79func WithPlugins(ctx context.Context, repository repository.Interface, names ...string) (Client, error) {
80 result := &data{
81 repository: repository,
82 }
83
84 load := func(names ...string) error {
85 for _, name := range names {
86 pluginData, err := result.repository.GetConnection(ctx, name)
87 if err != nil {
88 return err
89 }
90
91 result.plugins = append(result.plugins, pluginData)
92 }
93 return nil
94 }
95
96 // The following ensures that each plugin is loaded just one
97 // time, even when the same plugin has been requested multiple
98 // times.
99 loadingPlugins := stringset.From(names)
100 uniqueSortedPluginName := loadingPlugins.ToSortedList()
101
102 if err := load(uniqueSortedPluginName...); err != nil {
103 result.Close(ctx)
104 return nil, err
105 }
106
107 return result, nil
108}

Callers 1

innerNewClientFunction · 0.85

Calls 2

CloseMethod · 0.95
GetConnectionMethod · 0.65

Tested by

no test coverage detected