package main import ( "fmt" "io" "net/http" "strings" ) type Forge struct{} type ForgeVersion struct { Version string Time string Url string } func parseForgeVersions(html string) []ForgeVersion { lines := strings.Split(html, "\n") parsing := false foundTR := false buff := "" versions := []ForgeVersion{} for _, line := range lines { if strings.Contains(line, "") { parsing = true } else if strings.Contains(line, "") { parsing = false } else if parsing { if strings.Contains(line, "") { buff = "" foundTR = true } else if strings.Contains(line, "") { foundTR = false versions = append(versions, parseForgeVersion(buff)) } else if foundTR { buff += line + "\n" } } } return versions } func parseForgeVersion(html string) ForgeVersion { lines := strings.Split(html, "\n") version := ForgeVersion{} for ind, line := range lines { if strings.Contains(line, "") { version.Version = strings.TrimSpace(lines[ind+1]) } else if strings.Contains(line, "")[0] } else if strings.Contains(line, "https://adfoc.us") && strings.Contains(line, "installer.jar") { version.Url = strings.Split(strings.Split(line, "&url=")[1], "\">")[0] } } return version } func (Forge) GetForgeVersions(mcVersion string) ([]ForgeVersion, error) { resp, err := http.Get(fmt.Sprintf("https://files.minecraftforge.net/net/minecraftforge/forge/index_%s.html", mcVersion)) if err != nil { return []ForgeVersion{}, fmt.Errorf("unable to access minecraft forge index: %e", err) } defer resp.Body.Close() if resp.StatusCode != 200 { return []ForgeVersion{}, fmt.Errorf("unable to access minecraft forge index: %s", err) } data, _ := io.ReadAll(resp.Body) return parseForgeVersions(string(data)), nil }