You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
932 B

  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. package elastic
  5. import "context"
  6. // HasPlugin indicates whether the cluster has the named plugin.
  7. func (c *Client) HasPlugin(name string) (bool, error) {
  8. plugins, err := c.Plugins()
  9. if err != nil {
  10. return false, nil
  11. }
  12. for _, plugin := range plugins {
  13. if plugin == name {
  14. return true, nil
  15. }
  16. }
  17. return false, nil
  18. }
  19. // Plugins returns the list of all registered plugins.
  20. func (c *Client) Plugins() ([]string, error) {
  21. stats, err := c.ClusterStats().Do(context.Background())
  22. if err != nil {
  23. return nil, err
  24. }
  25. if stats == nil {
  26. return nil, err
  27. }
  28. if stats.Nodes == nil {
  29. return nil, err
  30. }
  31. var plugins []string
  32. for _, plugin := range stats.Nodes.Plugins {
  33. plugins = append(plugins, plugin.Name)
  34. }
  35. return plugins, nil
  36. }