package telegram
import (
"context"
"github.com/go-faster/errors"
"github.com/gotd/td/tg"
)
func (c *Client ) exportAuth (ctx context .Context , dcID int ) (*tg .AuthExportedAuthorization , error ) {
export , err := c .tg .AuthExportAuthorization (ctx , dcID )
if err != nil {
return nil , errors .Wrapf (err , "export auth to %d" , dcID )
}
return export , nil
}
type AuthTransferHandler func (ctx context .Context , client *Client , fn func (context .Context ) error ) error
func noopOnTransfer (ctx context .Context , _ *Client , fn func (context .Context ) error ) error {
return fn (ctx )
}
func (c *Client ) transfer (ctx context .Context , to *tg .Client , dc int ) (tg .AuthAuthorizationClass , error ) {
var out tg .AuthAuthorizationClass
if err := c .onTransfer (ctx , c , func (ctx context .Context ) error {
auth , err := c .exportAuth (ctx , dc )
if err != nil {
return errors .Wrapf (err , "export to %d" , dc )
}
req := &tg .AuthImportAuthorizationRequest {}
req .FillFrom (auth )
r , err := to .AuthImportAuthorization (ctx , req )
if err != nil {
return errors .Wrapf (err , "import from %d" , dc )
}
out = r
return nil
}); err != nil {
return nil , errors .Wrap (err , "onTransfer" )
}
return out , nil
}
The pages are generated with Golds v0.8.4 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .