forked from antsanchez/go-download-web
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathversion.go
57 lines (48 loc) · 1.08 KB
/
version.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
package main
import (
"bytes"
"io"
"net/http"
"os"
"path"
)
func checkVersion(cdUrl string, subPath string) error {
resp, err := http.Get(cdUrl + "/old/versions.json")
if err != nil {
return err
}
nowVersion, err := os.ReadFile(path.Join(subPath, "VERSION"))
if err != nil {
os.Create(path.Join(subPath, "VERSION"))
err = nil
}
newVersion, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
// version same return
if bytes.Compare(nowVersion, newVersion) == 0 {
os.Exit(0)
}
return os.WriteFile(path.Join(subPath, "VERSION"), newVersion, 0777)
}
func updateServiceINI(cdUrl string, subPath string) error {
resp, err := http.Get(cdUrl + "/servers.ini")
if err != nil {
return err
}
nowVersion, err := os.ReadFile(path.Join(subPath, ""))
if err != nil {
os.Create(path.Join(subPath, "servers.ini"))
err = nil
}
newVersion, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
// services.ini same return
if bytes.Compare(nowVersion, newVersion) == 0 {
return nil
}
return os.WriteFile(path.Join(subPath, "servers.ini"), newVersion, 0777)
}