feat: enhance user client context management and improve error handling

This commit is contained in:
krau
2025-12-19 13:48:55 +08:00
parent 018ed47949
commit d3cc56c8e6
5 changed files with 17 additions and 12 deletions

View File

@@ -23,23 +23,16 @@ var uc *gotgproto.Client
var ectx *ext.Context
func GetCtx() *ext.Context {
if uc == nil {
panic("User client is not initialized, please call Login first")
}
if ectx != nil {
return ectx
}
if uc == nil {
return nil
}
ectx = uc.CreateContext()
return ectx
}
func GetClient() *gotgproto.Client {
if uc == nil {
panic("User client is not initialized, please call Login first")
}
return uc
}
func Login(ctx context.Context) (*gotgproto.Client, error) {
log.FromContext(ctx).Debug("Logging in user client")
if uc != nil {