-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.go
59 lines (47 loc) · 1.25 KB
/
index.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
package update
import (
"encoding/json"
"github.com/TeaWeb/code/teaconst"
"github.com/TeaWeb/code/teautils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"io/ioutil"
"net/http"
"runtime"
"time"
)
type IndexAction actions.Action
// 检查版本更新
func (this *IndexAction) Run(params struct{}) {
this.Data["currentVersion"] = teaconst.TeaVersion
this.Show()
}
// 开始检查
func (this *IndexAction) RunPost() {
url := "http://teaos.cn/services/version?version=" + teaconst.TeaVersion
req, err := http.NewRequest("GET", url, nil)
if err != nil {
this.Fail("发生错误:" + err.Error())
}
req.Header.Set("User-Agent", runtime.GOOS+"/"+runtime.GOARCH)
client := teautils.SharedHttpClient(5 * time.Second)
resp, err := client.Do(req)
if err != nil {
this.Fail("无法连接TeaWeb服务:" + err.Error())
}
defer resp.Body.Close()
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
this.Fail("发生错误:" + err.Error())
}
m := maps.Map{}
err = json.Unmarshal(data, &m)
if err != nil {
this.Fail("发生错误:" + err.Error())
}
dataMap := maps.NewMap(m.Get("data"))
hasNew := dataMap.GetBool("hasNew")
this.Data["hasNew"] = hasNew
this.Data["latest"] = dataMap.GetString("latest")
this.Success()
}