mirror of
https://github.com/tiennm99/loldle.git
synced 2026-09-02 20:25:00 +00:00
feat: auto-detect latest champions version from Riot API
When championsVersion is empty, fetch the latest version from ddragon.leagueoflegends.com instead of requiring a hardcoded value.
This commit is contained in:
+31
-1
@@ -1,3 +1,33 @@
|
||||
package main
|
||||
|
||||
const championsVersion = "16.2.1"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Set this to pin a specific version. Leave empty to auto-detect latest.
|
||||
var championsVersion = ""
|
||||
|
||||
func getChampionsVersion() (string, error) {
|
||||
if championsVersion != "" {
|
||||
return championsVersion, nil
|
||||
}
|
||||
|
||||
resp, err := http.Get("https://ddragon.leagueoflegends.com/api/versions.json")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to fetch versions: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var versions []string
|
||||
if err := json.NewDecoder(resp.Body).Decode(&versions); err != nil {
|
||||
return "", fmt.Errorf("failed to decode versions: %w", err)
|
||||
}
|
||||
|
||||
if len(versions) == 0 {
|
||||
return "", fmt.Errorf("no versions found")
|
||||
}
|
||||
|
||||
return versions[0], nil
|
||||
}
|
||||
|
||||
+7
-1
@@ -11,7 +11,13 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
champions, err := parser.ParseChampions(championsVersion)
|
||||
version, err := getChampionsVersion()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get champions version: %v", err)
|
||||
}
|
||||
fmt.Printf("Using champions version: %s\n", version)
|
||||
|
||||
champions, err := parser.ParseChampions(version)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse champions: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user