From 2851aeb1bb34a5da81112d24ca6273b282eefc2c Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Mon, 13 Dec 2021 13:55:58 +0800 Subject: [PATCH] login: Fix nil Session --- login/kaptcha.go | 8 +++++--- login/login.go | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/login/kaptcha.go b/login/kaptcha.go index 6988642..04416e4 100644 --- a/login/kaptcha.go +++ b/login/kaptcha.go @@ -3,15 +3,17 @@ package login import ( "fmt" "time" + + "github.com/sunshineplan/gohttp" ) func (s *Session) Kaptcha(kaptcha func(*Session) (string, error)) error { - if s == nil { - s = New() - } if s.login == nil { return ErrNilLogin } + if s.Session == nil { + s.Session = gohttp.NewSession() + } data, err := kaptcha(s) if err != nil { diff --git a/login/login.go b/login/login.go index ae2bdf7..875e7a5 100644 --- a/login/login.go +++ b/login/login.go @@ -50,5 +50,11 @@ func (s *Session) SetLogin(fn func(*Session, interface{}) error) *Session { } func (s *Session) Login() error { + if s.login == nil { + return ErrNilLogin + } + if s.Session == nil { + s.Session = gohttp.NewSession() + } return s.login(s, nil) }