golang的私有化定制自动更新插件
shenwc
2024-11-26 f3ef5cf77a9ed8b93f5c0834cee10a26a219a5b7
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
package main
 
import (
    "fmt"
    "runtime"
 
    "github.com/zan8in/gologger"
    update "github.com/zan8in/goupdate"
    "github.com/zan8in/goupdate/progress"
    "github.com/zan8in/goupdate/stores/github"
)
 
func main() {
 
    // update polls(1) from tj/gh-polls on github
    m := &update.Manager{
        Command: "up",
        Store: &github.Store{
            Owner:   "apex",
            Repo:    "up",
            Version: "0.4.6",
        },
    }
 
    // fetch the target release
    release, err := m.GetRelease("0.4.5")
    if err != nil {
        gologger.Info().Msgf("error fetching release: %s", err)
        return
    }
 
    // find the tarball for this system
    a := release.FindTarball(runtime.GOOS, runtime.GOARCH)
    if a == nil {
        gologger.Error().Msg("no binary for your system")
        return
    }
 
    // whitespace
    fmt.Println()
 
    // download tarball to a tmp dir
    tarball, err := a.DownloadProxy(progress.Reader)
    if err != nil {
        gologger.Error().Msgf("error downloading: %s", err)
        return
    }
 
    // install it
    if err := m.Install(tarball); err != nil {
        gologger.Error().Msgf("error installing: %s", err)
        return
    }
 
    gologger.Info().Msgf("Updated to %s\n", release.Version)
}