-
Notifications
You must be signed in to change notification settings - Fork 3
/
bean.go
61 lines (51 loc) · 1.44 KB
/
bean.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package baiduOcrKit
import (
"github.com/richelieu-yang/chimera/v2/src/core/mapKit"
"time"
)
type (
accessToken struct {
// AccessToken 要获取的Access Token
AccessToken string `mapstructure:"access_token"`
// ExpiresIn Access Token的有效期(秒为单位,有效期30天)
ExpiresIn uint32 `mapstructure:"expires_in"`
ExpireTime time.Time
RefreshToken string `mapstructure:"refresh_token"`
Scope string `mapstructure:"scope"`
SessionKey string `mapstructure:"session_key"`
SessionSecret string `mapstructure:"session_secret"`
}
Words struct {
LogId uint64 `mapstructure:"log_id"`
WordsResultNum uint32 `mapstructure:"words_result_num"`
WordsResults []WordsResult `mapstructure:"words_result"`
}
WordsResult struct {
Words string `mapstructure:"words"`
}
)
func (token *accessToken) isExpired() bool {
return time.Now().After(token.ExpireTime)
}
func parseMapToAccessToken(m map[string]interface{}) (*accessToken, error) {
if !mapKit.ContainKeys(m, "access_token", "expires_in") {
return nil, nil
}
token := &accessToken{}
err := mapKit.Decode(m, token)
if err != nil {
return nil, err
}
return token, nil
}
func parseMapToWords(m map[string]interface{}) (*Words, error) {
if !mapKit.ContainKeys(m, "log_id", "words_result_num", "words_result") {
return nil, nil
}
words := &Words{}
err := mapKit.Decode(m, words)
if err != nil {
return nil, err
}
return words, nil
}