Repository navigation
Expand file tree
/
Copy pathtest-update.go
More file actions
81 lines (68 loc) · 1.96 KB
/
Copy pathtest-update.go
File metadata and controls
81 lines (68 loc) · 1.96 KB
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
80
81
//go:build ignore
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
)
// GitHubRelease GitHub Release 结构
type GitHubRelease struct {
TagName string `json:"tag_name"`
Body string `json:"body"`
Assets []struct {
Name string `json:"name"`
BrowserDownloadURL string `json:"browser_download_url"`
Size int64 `json:"size"`
} `json:"assets"`
}
func main() {
client := &http.Client{}
releaseURL := "https://api.github.com/repos/Rogers-F/code-switch-R/releases/latest"
req, err := http.NewRequest("GET", releaseURL, nil)
if err != nil {
log.Fatal("创建请求失败:", err)
}
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("User-Agent", "CodeSwitch-Test")
resp, err := client.Do(req)
if err != nil {
log.Fatal("请求失败:", err)
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Fatalf("GitHub API 返回错误状态码: %d", resp.StatusCode)
}
var release GitHubRelease
if err := json.NewDecoder(resp.Body).Decode(&release); err != nil {
log.Fatal("解析响应失败:", err)
}
fmt.Printf("✅ 最新版本: %s\n", release.TagName)
fmt.Printf("📝 发布说明:\n%s\n\n", release.Body)
fmt.Printf("📦 可用的安装包:\n")
for _, asset := range release.Assets {
fmt.Printf(" - %s (%d bytes)\n %s\n", asset.Name, asset.Size, asset.BrowserDownloadURL)
}
// 检查必需的文件是否存在
requiredFiles := []string{
"CodeSwitch-amd64-installer.exe", // Windows安装器
"CodeSwitch.exe", // Windows便携版
"codeswitch-macos-arm64.zip", // macOS ARM
"codeswitch-macos-amd64.zip", // macOS Intel
}
fmt.Printf("\n🔍 检查必需文件:\n")
for _, required := range requiredFiles {
found := false
for _, asset := range release.Assets {
if asset.Name == required {
found = true
break
}
}
if found {
fmt.Printf(" ✅ %s\n", required)
} else {
fmt.Printf(" ❌ %s (缺失)\n", required)
}
}
}