Exemple #1
0
// ConnectTimeout returns a new connected klient instance to the given
// queryString. The klient is ready to use. It's tries to connect for the given
// timeout duration
func ConnectTimeout(k *kite.Kite, queryString string, t time.Duration) (*Klient, error) {
	query, err := protocol.KiteFromString(queryString)
	if err != nil {
		return nil, err
	}

	k.Log.Debug("Connecting with timeout=%s to Klient: %s", t, queryString)

	kites, err := k.GetKites(query.Query())
	if err != nil {
		return nil, err
	}

	remoteKite := kites[0]
	remoteKite.ReadBufferSize = 512
	remoteKite.WriteBufferSize = 512

	err = remoteKite.DialTimeout(t)
	if err != nil {
		// If kite exists but dialing failed, we still return the *Klient
		// value, althought not connected, in order to allow the caller
		// inspect the URL and eventually recover.
		err = ErrDialingFailed
	}

	k.Log.Debug("Dialing %q (%s) kite failed: %s", queryString, remoteKite.URL, err)

	return &Klient{
		kite:     k,
		Client:   remoteKite,
		Username: remoteKite.Username,
	}, err
}
Exemple #2
0
// Exists checks whether the given queryString exists in Kontrol or not
func Exists(k *kite.Kite, queryString string) error {
	query, err := protocol.KiteFromString(queryString)
	if err != nil {
		return err
	}

	k.Log.Debug("Checking whether %s exists in Kontrol", queryString)

	// an error indicates a non existing klient or another error.
	_, err = k.GetKites(query.Query())
	if err != nil {
		return err
	}

	return nil
}