Skip to content

Commit

Permalink
login: Fix nil Session
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshineplan committed Dec 13, 2021
1 parent 14cc7c4 commit 2851aeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 5 additions & 3 deletions login/kaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 2851aeb

Please sign in to comment.