-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
101 lines (84 loc) · 1.73 KB
/
config.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ylyOpenApi
import (
"crypto/md5"
"encoding/hex"
)
type Config struct {
clientId string
clientSecret string
requestUrl string
token Token
logger YlySdkLogger
bLogger bool
}
type YlySdkLogger interface {
Info(message string)
Error(message string)
}
type Token struct {
Error int
Error_description string
Body TokenBody
}
type TokenBody struct {
Access_token string
Refresh_token string
Expires_in int
Machine_code string
}
func NewConfig(cid string, secret string) Config {
conf := Config{}
conf.SetClientId(cid)
conf.SetClientSecret(secret)
return conf
}
func (conf *Config) SetClientId(cid string) {
conf.clientId = cid
}
func (conf *Config) SetClientSecret(secret string) {
conf.clientSecret = secret
}
func (conf *Config) SetRequestUrl(reqUrl string) {
conf.requestUrl = reqUrl
}
func (conf *Config) SetToken(token Token) {
conf.token = token
}
func (conf *Config) SetLogger(logger YlySdkLogger) {
conf.logger = logger
conf.bLogger = true
}
func (conf *Config) GetSign(timestamp string) string {
h := md5.New()
h.Write([]byte(conf.clientId + timestamp + conf.clientSecret))
cipherStr := h.Sum(nil)
return hex.EncodeToString(cipherStr)
}
func (conf *Config) GetHost() string {
if conf.requestUrl != "" {
return conf.requestUrl
}
return RequestUrl()
}
func (conf *Config) diagnosis() {
if conf.logger != nil {
conf.bLogger = true
}else {
conf.bLogger = false
}
}
func (conf *Config) info(info string) {
conf.diagnosis()
if conf.bLogger {
conf.logger.Info(info)
}
}
func (conf *Config) error(err string) {
conf.diagnosis()
if conf.bLogger {
conf.logger.Error(err)
}
}
func RequestUrl() string {
return "https://open-api.10ss.net"
}