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
| package qiniu
|
| import (
| "fmt"
| "runtime"
| "strings"
|
| "github.com/zan8in/goupdate/progress"
| )
|
| type Store struct {
| Owner string
| Repo string
| Version string
| }
|
| type QiniuResult struct {
| Status int // update success = 1; have latest version = 2;
| LatestVersion string
| }
|
| func init() {
| fmt.Printf("qiniu store %s", "init!")
| }
|
| // 更新最新版本
| // owner = zan8in
| // repo = afrog
| // version = 2.8.8 当前版本
| func Update(owner, repo, version string) (*QiniuResult, error) {
| var (
| result = &QiniuResult{}
| err error
| )
|
| var command string
| switch runtime.GOOS {
| case "windows":
| command = repo + ".exe"
| default:
| command = repo
| }
|
| s := &Store{
| Owner: owner,
| Repo: repo,
| Version: version,
| }
|
| m := update.Manager{
| Command: command,
| }
|
| asset, err := s.LatestGitReleases()
| if err != nil {
| if strings.Contains(err.Error(), update.LatestVersionTips) {
| result.LatestVersion = asset.LatestVersion
| result.Status = 2
| return result, nil
| }
| return nil, err
| }
|
| // download tarball to a tmp dir
| tarball, err := asset.DownloadProxy(progress.Reader)
| if err != nil {
| return nil, fmt.Errorf("error downloading: %s", err)
| }
|
| // install it
| if err := m.Install(tarball); err != nil {
| return nil, fmt.Errorf("error installing: %s", err)
| }
|
| // gologger.Info().Msgf("Successfully updated to %s %s\n", command, s.Version)
| result.LatestVersion = asset.LatestVersion
| result.Status = 1
| return result, nil
| }
|
|