search

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterExists

func ClusterExists(c *om.AutomationConfig, name string) bool

ClusterExists return true if a cluster exists for the given name

Example

This example demonstrates searching a cluster in an automation config.

package main

import (
	"fmt"

	"github.com/mongodb/mongocli/internal/fixtures"
	"github.com/mongodb/mongocli/internal/search"
)

func main() {
	a := fixtures.AutomationConfig()
	x := "myReplicaSet"
	found := search.ClusterExists(a, x)
	if found {
		fmt.Printf("found %v\n", x)
	} else {
		fmt.Printf("%s not found\n", x)
	}
}
Output:

found myReplicaSet

func Members

func Members(a []om.Member, f func(om.Member) bool) (int, bool)

Members return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, Members returns n and false

Example

This example demonstrates searching a list of members by host.

package main

import (
	"fmt"

	om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
	"github.com/mongodb/mongocli/internal/fixtures"
	"github.com/mongodb/mongocli/internal/search"
)

func main() {
	a := fixtures.AutomationConfig().ReplicaSets[0].Members
	x := "myReplicaSet_2"
	i, found := search.Members(a, func(m om.Member) bool { return m.Host == x })
	if i < len(a) && found {
		fmt.Printf("found %v at index %d\n", x, i)
	} else {
		fmt.Printf("%s not found\n", x)
	}
}
Output:

found myReplicaSet_2 at index 1

func Processes

func Processes(a []*om.Process, f func(*om.Process) bool) (int, bool)

Processes return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, Processes returns n and false

Example

This example demonstrates searching a list of processes by name.

package main

import (
	"fmt"

	om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
	"github.com/mongodb/mongocli/internal/fixtures"
	"github.com/mongodb/mongocli/internal/search"
)

func main() {
	a := fixtures.AutomationConfig().Processes
	x := "myReplicaSet_2"
	i, found := search.Processes(a, func(p *om.Process) bool { return p.Name == x })
	if i < len(a) && found {
		fmt.Printf("found %v at index %d\n", x, i)
	} else {
		fmt.Printf("%s not found\n", x)
	}
}
Output:

found myReplicaSet_2 at index 1

func ReplicaSets

func ReplicaSets(a []*om.ReplicaSet, f func(*om.ReplicaSet) bool) (int, bool)

Members return the smallest index i in [0, n) at which f(i) is true, assuming that on the range [0, n), f(i) == true implies f(i+1) == true. returns the first true index. If there is no such index, Members returns n and false

Example

This example demonstrates searching a list of replica sets by ID.

package main

import (
	"fmt"

	om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
	"github.com/mongodb/mongocli/internal/fixtures"
	"github.com/mongodb/mongocli/internal/search"
)

func main() {
	a := fixtures.AutomationConfig().ReplicaSets
	x := "myReplicaSet"
	i, found := search.ReplicaSets(a, func(r *om.ReplicaSet) bool { return r.ID == x })
	if i < len(a) && found {
		fmt.Printf("found %v at index %d\n", x, i)
	} else {
		fmt.Printf("%s not found\n", x)
	}
}
Output:

found myReplicaSet at index 0

func StringInSlice

func StringInSlice(a []string, x string) bool
Example

This example demonstrates searching a list.

package main

import (
	"fmt"

	"github.com/mongodb/mongocli/internal/search"
)

func main() {
	a := []string{"a", "b", "c"}
	x := "a"

	if search.StringInSlice(a, x) {
		fmt.Printf("found %s in %v\n", x, a)
	} else {
		fmt.Printf("%s not found in %v\n", x, a)
	}
}
Output:

found a in [a b c]

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL