package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type AuthSignInRequest struct {
Flags bin .Fields
PhoneNumber string
PhoneCodeHash string
PhoneCode string
EmailVerification EmailVerificationClass
}
const AuthSignInRequestTypeID = 0x8d52a951
var (
_ bin .Encoder = &AuthSignInRequest {}
_ bin .Decoder = &AuthSignInRequest {}
_ bin .BareEncoder = &AuthSignInRequest {}
_ bin .BareDecoder = &AuthSignInRequest {}
)
func (s *AuthSignInRequest ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .PhoneNumber == "" ) {
return false
}
if !(s .PhoneCodeHash == "" ) {
return false
}
if !(s .PhoneCode == "" ) {
return false
}
if !(s .EmailVerification == nil ) {
return false
}
return true
}
func (s *AuthSignInRequest ) String () string {
if s == nil {
return "AuthSignInRequest(nil)"
}
type Alias AuthSignInRequest
return fmt .Sprintf ("AuthSignInRequest%+v" , Alias (*s ))
}
func (s *AuthSignInRequest ) FillFrom (from interface {
GetPhoneNumber () (value string )
GetPhoneCodeHash () (value string )
GetPhoneCode () (value string , ok bool )
GetEmailVerification () (value EmailVerificationClass , ok bool )
}) {
s .PhoneNumber = from .GetPhoneNumber ()
s .PhoneCodeHash = from .GetPhoneCodeHash ()
if val , ok := from .GetPhoneCode (); ok {
s .PhoneCode = val
}
if val , ok := from .GetEmailVerification (); ok {
s .EmailVerification = val
}
}
func (*AuthSignInRequest ) TypeID () uint32 {
return AuthSignInRequestTypeID
}
func (*AuthSignInRequest ) TypeName () string {
return "auth.signIn"
}
func (s *AuthSignInRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "auth.signIn" ,
ID : AuthSignInRequestTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "PhoneNumber" ,
SchemaName : "phone_number" ,
},
{
Name : "PhoneCodeHash" ,
SchemaName : "phone_code_hash" ,
},
{
Name : "PhoneCode" ,
SchemaName : "phone_code" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "EmailVerification" ,
SchemaName : "email_verification" ,
Null : !s .Flags .Has (1 ),
},
}
return typ
}
func (s *AuthSignInRequest ) SetFlags () {
if !(s .PhoneCode == "" ) {
s .Flags .Set (0 )
}
if !(s .EmailVerification == nil ) {
s .Flags .Set (1 )
}
}
func (s *AuthSignInRequest ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode auth.signIn#8d52a951 as nil" )
}
b .PutID (AuthSignInRequestTypeID )
return s .EncodeBare (b )
}
func (s *AuthSignInRequest ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode auth.signIn#8d52a951 as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.signIn#8d52a951: field flags: %w" , err )
}
b .PutString (s .PhoneNumber )
b .PutString (s .PhoneCodeHash )
if s .Flags .Has (0 ) {
b .PutString (s .PhoneCode )
}
if s .Flags .Has (1 ) {
if s .EmailVerification == nil {
return fmt .Errorf ("unable to encode auth.signIn#8d52a951: field email_verification is nil" )
}
if err := s .EmailVerification .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode auth.signIn#8d52a951: field email_verification: %w" , err )
}
}
return nil
}
func (s *AuthSignInRequest ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode auth.signIn#8d52a951 to nil" )
}
if err := b .ConsumeID (AuthSignInRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: %w" , err )
}
return s .DecodeBare (b )
}
func (s *AuthSignInRequest ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode auth.signIn#8d52a951 to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: field flags: %w" , err )
}
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: field phone_number: %w" , err )
}
s .PhoneNumber = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: field phone_code_hash: %w" , err )
}
s .PhoneCodeHash = value
}
if s .Flags .Has (0 ) {
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: field phone_code: %w" , err )
}
s .PhoneCode = value
}
if s .Flags .Has (1 ) {
value , err := DecodeEmailVerification (b )
if err != nil {
return fmt .Errorf ("unable to decode auth.signIn#8d52a951: field email_verification: %w" , err )
}
s .EmailVerification = value
}
return nil
}
func (s *AuthSignInRequest ) GetPhoneNumber () (value string ) {
if s == nil {
return
}
return s .PhoneNumber
}
func (s *AuthSignInRequest ) GetPhoneCodeHash () (value string ) {
if s == nil {
return
}
return s .PhoneCodeHash
}
func (s *AuthSignInRequest ) SetPhoneCode (value string ) {
s .Flags .Set (0 )
s .PhoneCode = value
}
func (s *AuthSignInRequest ) GetPhoneCode () (value string , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (0 ) {
return value , false
}
return s .PhoneCode , true
}
func (s *AuthSignInRequest ) SetEmailVerification (value EmailVerificationClass ) {
s .Flags .Set (1 )
s .EmailVerification = value
}
func (s *AuthSignInRequest ) GetEmailVerification () (value EmailVerificationClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (1 ) {
return value , false
}
return s .EmailVerification , true
}
func (c *Client ) AuthSignIn (ctx context .Context , request *AuthSignInRequest ) (AuthAuthorizationClass , error ) {
var result AuthAuthorizationBox
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return result .Authorization , nil
}
The pages are generated with Golds v0.6.7 . (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 @Go100and1 (reachable from the left QR code) to get the latest news of Golds .