func (c *Client) Find(searchKey, searchValue string) (*Agent, error) {
	if searchKey == "" {
		searchKey = "name"
	}

	// validate the search key
	switch searchKey {
	case "id", "name", "ip":
		break
	default:
		return nil, fmt.Errorf("search key %q is invalid", searchKey)
	}

	list, err := c.List()
	if err != nil {
		return nil, err
	}

	for _, item := range list {
		value := ""

		switch searchKey {
		case "id":
			value = item.ID
		case "name":
			value = item.Name
		case "ip":
			value = item.IP
		default:
			return nil, fmt.Errorf("search key %q is invalid", searchKey)
		}

		if strings.TrimSpace(strings.ToLower(value)) == strings.TrimSpace(strings.ToLower(searchValue)) {
			return item, nil
		}
	}

	return nil, nil
}
// Finds an agent using a regex search on the name
Finds an agent using a regex search on the name
// Finds an agent using a regex search on the name
func (c *Client) Find(searchKey, searchValue string) (*Agent, error) {
	if searchKey == "" {
		searchKey = "name"
	}
	switch searchKey {
	case "id", "name", "ip":
		break
	default:
		return nil, fmt.Errorf("search key %q is invalid", searchKey)
	}
	list, err := c.List()
	if err != nil {
		return nil, err
	}
	for _, item := range list {
		value := ""
		switch searchKey {
		case "id":
			value = item.ID
		case "name":
			value = item.Name
		case "ip":
			value = item.IP
		default:
			return nil, fmt.Errorf("search key %q is invalid", searchKey)
		}
		if strings.TrimSpace(strings.ToLower(value)) == strings.TrimSpace(strings.ToLower(searchValue)) {
			return item, nil
		}
	}
	return nil, nil
}
func ( c * Client ) Find ( searchKey , searchValue string ) ( * Agent , error ) { if searchKey == " " { searchKey = " " } switch searchKey { case " " , " " , " " : break default : return nil , fmt . Errorf ( " " , searchKey ) } list , err := c . List ( ) if err != nil { return nil , err } for _ , item := range list { value := " " switch searchKey { case " " : value = item . ID case " " : value = item . Name case " " : value = item . IP default : return nil , fmt . Errorf ( " " , searchKey ) } if strings . TrimSpace ( strings . ToLower ( value ) ) == strings . TrimSpace ( strings . ToLower ( searchValue ) ) { return item , nil } } return nil , nil }
Finds an agent using a regex search on the name
Finds an agent using a regex search on the name
// validate the search key