add Close() to auth handlers
This commit is contained in:
parent
7e94393f03
commit
ef52e705ae
|
@ -10,9 +10,12 @@ var ErrNotSupportedAuthorizationState = errors.New("not supported state")
|
||||||
|
|
||||||
type AuthorizationStateHandler interface {
|
type AuthorizationStateHandler interface {
|
||||||
Handle(client *Client, state AuthorizationState) error
|
Handle(client *Client, state AuthorizationState) error
|
||||||
|
Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandler) error {
|
func Authorize(client *Client, authorizationStateHandler AuthorizationStateHandler) error {
|
||||||
|
defer authorizationStateHandler.Close()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
state, err := client.GetAuthorizationState()
|
state, err := client.GetAuthorizationState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -91,14 +94,6 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
||||||
return err
|
return err
|
||||||
|
|
||||||
case TypeAuthorizationStateReady:
|
case TypeAuthorizationStateReady:
|
||||||
close(stateHandler.TdlibParameters)
|
|
||||||
close(stateHandler.PhoneNumber)
|
|
||||||
close(stateHandler.Code)
|
|
||||||
close(stateHandler.State)
|
|
||||||
close(stateHandler.FirstName)
|
|
||||||
close(stateHandler.LastName)
|
|
||||||
close(stateHandler.Password)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case TypeAuthorizationStateLoggingOut:
|
case TypeAuthorizationStateLoggingOut:
|
||||||
|
@ -114,6 +109,16 @@ func (stateHandler *clientAuthorizer) Handle(client *Client, state Authorization
|
||||||
return ErrNotSupportedAuthorizationState
|
return ErrNotSupportedAuthorizationState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stateHandler *clientAuthorizer) Close() {
|
||||||
|
close(stateHandler.TdlibParameters)
|
||||||
|
close(stateHandler.PhoneNumber)
|
||||||
|
close(stateHandler.Code)
|
||||||
|
close(stateHandler.State)
|
||||||
|
close(stateHandler.FirstName)
|
||||||
|
close(stateHandler.LastName)
|
||||||
|
close(stateHandler.Password)
|
||||||
|
}
|
||||||
|
|
||||||
func CliInteractor(clientAuthorizer *clientAuthorizer) {
|
func CliInteractor(clientAuthorizer *clientAuthorizer) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -207,10 +212,6 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
|
||||||
return ErrNotSupportedAuthorizationState
|
return ErrNotSupportedAuthorizationState
|
||||||
|
|
||||||
case TypeAuthorizationStateReady:
|
case TypeAuthorizationStateReady:
|
||||||
close(stateHandler.TdlibParameters)
|
|
||||||
close(stateHandler.Token)
|
|
||||||
close(stateHandler.State)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case TypeAuthorizationStateLoggingOut:
|
case TypeAuthorizationStateLoggingOut:
|
||||||
|
@ -225,3 +226,9 @@ func (stateHandler *botAuthorizer) Handle(client *Client, state AuthorizationSta
|
||||||
|
|
||||||
return ErrNotSupportedAuthorizationState
|
return ErrNotSupportedAuthorizationState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (stateHandler *botAuthorizer) Close() {
|
||||||
|
close(stateHandler.TdlibParameters)
|
||||||
|
close(stateHandler.Token)
|
||||||
|
close(stateHandler.State)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue