-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoken.go
More file actions
48 lines (40 loc) · 806 Bytes
/
token.go
File metadata and controls
48 lines (40 loc) · 806 Bytes
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
package main
import (
"fmt"
"io/ioutil"
"os"
)
const (
tokenFile = ".syncd-token"
)
var _token string
func TokenFail() {
RemoveToken()
panic(fmt.Sprintf("登录失败, 请设置正确的账号密码并执行登录"))
}
func RemoveToken() {
if err := os.Remove(tokenFile); err != nil {
logger.Println("remove .token failed")
}
}
func SetToken(token string) {
//logger.Println("set token:", token)
err := ioutil.WriteFile(tokenFile, []byte(token), 0644)
if err != nil {
panic(err)
}
_token = token
}
func GetToken() string {
if _token == "" {
tokenByte, err := ioutil.ReadFile(tokenFile)
if err != nil {
panic("请先登录")
//NewRequest(syncdCfg.access).Login()
//return ""
}
_token = string(tokenByte)
}
//logger.Println("get token:", _token)
return _token
}