Skip to content

Commit 6979a83

Browse files
committed
feat(emozi): add api IsValid
1 parent b54f37c commit 6979a83

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

emozi/login.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/hex"
77
"encoding/json"
88
"errors"
9+
"net/http"
910
"net/url"
1011

1112
"github.com/FloatTech/floatbox/binary"
@@ -65,3 +66,15 @@ func (usr *User) Login() error {
6566
usr.auth = r.Get("result.token").Str
6667
return nil
6768
}
69+
70+
// IsValid 检查是否有效
71+
func (usr *User) IsValid() bool {
72+
if usr.name == "" || usr.pswd == "" || usr.auth == "" {
73+
return false
74+
}
75+
_, err := web.RequestDataWithHeaders(http.DefaultClient, api+"", "GET", func(r *http.Request) error {
76+
r.Header.Set("Authorization", usr.auth)
77+
return nil
78+
}, nil)
79+
return err == nil
80+
}

0 commit comments

Comments
 (0)