MCPcopy Index your code
hub / github.com/koding/kite / hello

Method hello

kontrol/helper_test.go:188–241  ·  view source on GitHub ↗
(remote *HelloKite, force bool)

Source from the content-addressed store, hash-verified

186}
187
188func (hk *HelloKite) hello(remote *HelloKite, force bool) (string, error) {
189 const timeout = 10 * time.Second
190
191 c, ok := hk.clients[remote.Kite.Id]
192 if !ok || force {
193 if hk.Token {
194 query := &protocol.KontrolQuery{
195 ID: remote.Kite.Id,
196 }
197
198 kites, err := hk.Kite.GetKites(query)
199 if err != nil {
200 return "", fmt.Errorf("%s: %+v", err, query)
201 }
202
203 if len(kites) != 1 {
204 return "", fmt.Errorf("%s: expected to get 1 kite, got %d", remote.Kite.Id, len(kites))
205 }
206
207 c = kites[0]
208 c.OnTokenExpire(hk.onTokenExpire)
209 c.OnTokenRenew(hk.onTokenRenew)
210 } else {
211 c = hk.Kite.NewClient(remote.URL.String())
212 c.Auth = &kite.Auth{
213 Type: "kiteKey",
214 Key: hk.Kite.KiteKey(),
215 }
216 }
217
218 if err := c.DialTimeout(timeout); err != nil {
219 return "", err
220 }
221
222 hk.clients[remote.Kite.Id] = c
223 }
224
225 res, err := c.TellWithTimeout("hello", timeout)
226 if err != nil {
227 // TODO(rjeczalik): remove "timeout" - see comment in (*Client).sendHub method
228 if e, ok := err.(*kite.Error); ok && (e.Type == "disconnect" || e.Type == "timeout") && !force {
229 return hk.hello(remote, true)
230 }
231
232 return "", err
233 }
234
235 s, err := res.String()
236 if err != nil {
237 return "", err
238 }
239
240 return s, nil
241}
242
243func (hk *HelloKite) Close() error {
244 for _, c := range hk.clients {

Callers 1

HelloMethod · 0.95

Calls 8

GetKitesMethod · 0.80
OnTokenExpireMethod · 0.80
OnTokenRenewMethod · 0.80
NewClientMethod · 0.80
KiteKeyMethod · 0.80
DialTimeoutMethod · 0.80
TellWithTimeoutMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected