예제 #1
0
파일: klient.go 프로젝트: koding/koding
// 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
}
예제 #2
0
파일: pool.go 프로젝트: BigRoom/zombies
func bindHandlers(k *kite.Kite) {
	k.HandleFunc("add", addZombie).
		DisableAuthentication()

	k.HandleFunc("send", sendZombie).
		DisableAuthentication()

	k.HandleFunc("join", joinZombie).
		DisableAuthentication()

	k.HandleFunc("exists", existsZombie).
		DisableAuthentication()

	k.HandleFunc("channels", channelsZombie).
		DisableAuthentication()
}
예제 #3
0
파일: klient.go 프로젝트: koding/koding
// 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
}
예제 #4
0
파일: kite.go 프로젝트: koding/koding
func setupKite(k *kite.Kite, conf *Config) *kite.Kite {

	k.Config.Port = conf.Port

	if conf.Region != "" {
		k.Config.Region = conf.Region
	}

	if conf.Environment != "" {
		k.Config.Environment = conf.Environment
	}

	if conf.Debug {
		k.SetLogLevel(kite.DEBUG)
	}

	if conf.Test {
		k.Config.DisableAuthentication = true
	}

	return k
}