package backend import ( "encoding/json" "fmt" "log" "net/http" "strings" ) type giteaResponse struct { Id int `json:"id"` Name string `json:"name"` Assets []assetResponse `json:"assets"` } type assetResponse struct { Id int `json:"id"` Name string `json:"name"` DownloadUrl string `json:"browser_download_url"` } func CheckLatest() string { resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest") if err != nil { log.Fatalln(err) } defer resp.Body.Close() //Create a variable of the same type as our model var cResp giteaResponse //Decode the data if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil { fmt.Println(err) log.Fatal("ooopsss! an error occurred, please try again") } log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name) return cResp.Name } func ListAssetsOfLatest() []string { resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest") if err != nil { log.Fatalln(err) } defer resp.Body.Close() //Create a variable of the same type as our model var cResp giteaResponse //Decode the data if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil { fmt.Println(err) log.Fatal("ooopsss! an error occurred, please try again") } log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name) var assets []string for _, asset := range cResp.Assets { log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name) assets = append(assets, asset.Name) } return assets } func DownloadLatestWindows() string { resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest") if err != nil { log.Fatalln(err) } defer resp.Body.Close() //Create a variable of the same type as our model var cResp giteaResponse //Decode the data if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil { fmt.Println(err) log.Fatal("ooopsss! an error occurred, please try again") } log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name) for _, asset := range cResp.Assets { log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name) if strings.HasSuffix(asset.Name, ".exe") { return asset.DownloadUrl } } return "" } func DownloadLatestLinux() string { resp, err := http.Get("https://gitea.sanplex.tech/api/v1/repos/sansan/MusicPlayer/releases/latest") if err != nil { log.Fatalln(err) } defer resp.Body.Close() //Create a variable of the same type as our model var cResp giteaResponse //Decode the data if err := json.NewDecoder(resp.Body).Decode(&cResp); err != nil { fmt.Println(err) log.Fatal("ooopsss! an error occurred, please try again") } log.Printf("Id: %v, Name: %v", cResp.Id, cResp.Name) for _, asset := range cResp.Assets { log.Printf("Id: %v, Name: %v, Asset: %v", cResp.Id, cResp.Name, asset.Name) if strings.HasSuffix(asset.Name, ".x86_64") { return asset.DownloadUrl } } return "" }