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:
2026-04-05 12:13:43 +07:00
parent a12b5d2b5d
commit eddcfe25fa
2 changed files with 38 additions and 2 deletions
+31 -1
View File
@@ -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
View File
@@ -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)
}