This repository was archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.go
More file actions
60 lines (52 loc) · 1.32 KB
/
data.go
File metadata and controls
60 lines (52 loc) · 1.32 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
package main
import (
"encoding/json"
"net/http"
"time"
)
type GenshinData struct {
Data struct {
Game *GameData `json:"game"`
PreGame *GameData `json:"pre_download_game"`
} `json:"data"`
}
type GameData struct {
Latest struct {
Ver string `json:"version"`
} `json:"latest"`
Diffs []*Diff `json:"diffs"`
}
type Diff struct {
Name string `json:"name"`
Ver string `json:"version"`
Path string `json:"path"`
Size string `json:"package_size"`
Hash string `json:"md5"`
Voice []struct {
Lang string `json:"language"`
Name string `json:"name"`
Path string `json:"path"`
Size string `json:"package_size"`
Hash string `json:"md5"`
} `json:"voice_packs"`
}
func getData() (*GenshinData, error) {
URL := "https://hk4e-launcher-static.hoyoverse.com/hk4e_global/mdk/launcher/api/resource?channel_id=1&key=gcStgarh&launcher_id=10&sub_channel_id=0"
client := &http.Client{Timeout: 10 * time.Second}
req, err := http.NewRequest(http.MethodGet, URL, http.NoBody)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "Mozilla/5.0")
resp, err := client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var data *GenshinData
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
return nil, err
}
return data, nil
}