@@ -328,12 +328,12 @@ func (c *Client) GenerateKey(key, channel, permissions string, ttl int) (string,
328
328
}
329
329
330
330
// CreatePrivateLink sends a request to create a private link.
331
- func (c * Client ) CreatePrivateLink (key , channel , name string , subscribe bool , options ... Option ) (* Link , error ) {
331
+ func (c * Client ) CreatePrivateLink (key , channel , name string , optionalHandler MessageHandler , options ... Option ) (* Link , error ) {
332
332
resp , err := c .request ("link" , & linkRequest {
333
333
Name : name ,
334
334
Key : key ,
335
335
Channel : formatTopic ("" , channel , options ),
336
- Subscribe : subscribe ,
336
+ Subscribe : optionalHandler != nil ,
337
337
Private : true ,
338
338
})
339
339
if err != nil {
@@ -342,18 +342,23 @@ func (c *Client) CreatePrivateLink(key, channel, name string, subscribe bool, op
342
342
343
343
// Cast the response and return it
344
344
if result , ok := resp .(* Link ); ok {
345
+ if optionalHandler != nil {
346
+ c .handlers .AddHandler (result .Channel , optionalHandler )
347
+ }
348
+
345
349
return result , nil
346
350
}
351
+
347
352
return nil , ErrUnmarshal
348
353
}
349
354
350
355
// CreateLink sends a request to create a default link.
351
- func (c * Client ) CreateLink (key , channel , name string , subscribe bool , options ... Option ) (* Link , error ) {
356
+ func (c * Client ) CreateLink (key , channel , name string , optionalHandler MessageHandler , options ... Option ) (* Link , error ) {
352
357
resp , err := c .request ("link" , & linkRequest {
353
358
Name : name ,
354
359
Key : key ,
355
360
Channel : formatTopic ("" , channel , options ),
356
- Subscribe : subscribe ,
361
+ Subscribe : optionalHandler != nil ,
357
362
Private : false ,
358
363
})
359
364
@@ -363,6 +368,10 @@ func (c *Client) CreateLink(key, channel, name string, subscribe bool, options .
363
368
364
369
// Cast the response and return it
365
370
if result , ok := resp .(* Link ); ok {
371
+ if optionalHandler != nil {
372
+ c .handlers .AddHandler (result .Channel , optionalHandler )
373
+ }
374
+
366
375
return result , nil
367
376
}
368
377
return nil , ErrUnmarshal
0 commit comments