Debian Codegraph @

plugins.go

raw
1 // Copyright 2012-present Oliver Eilhard. All rights reserved.
2 // Use of this source code is governed by a MIT-license.
3 // See http://olivere.mit-license.org/license.txt for details.
4
5 package elastic
6
7 import "context"
8
9 // HasPlugin indicates whether the cluster has the named plugin.
10 func (c *Client) HasPlugin(name string) (bool, error) {
11 plugins, err := c.Plugins()
12 if err != nil {
13 return false, nil
14 }
15 for _, plugin := range plugins {
16 if plugin == name {
17 return true, nil
18 }
19 }
20 return false, nil
21 }
22
23 // Plugins returns the list of all registered plugins.
24 func (c *Client) Plugins() ([]string, error) {
25 stats, err := c.ClusterStats().Do(context.Background())
26 if err != nil {
27 return nil, err
28 }
29 if stats == nil {
30 return nil, err
31 }
32 if stats.Nodes == nil {
33 return nil, err
34 }
35 var plugins []string
36 for _, plugin := range stats.Nodes.Plugins {
37 plugins = append(plugins, plugin.Name)
38 }
39 return plugins, nil
40 }