58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"io"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type Fabric struct {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
type FabricDefinition struct {
|
||
|
Separator string
|
||
|
Build int
|
||
|
Maven string
|
||
|
Version string
|
||
|
Stable bool
|
||
|
}
|
||
|
|
||
|
type FabricLibrary struct {
|
||
|
Name string
|
||
|
Url string
|
||
|
}
|
||
|
|
||
|
type FabricLibraries struct {
|
||
|
Client []FabricLibrary
|
||
|
Common []FabricLibrary
|
||
|
Server []FabricLibrary
|
||
|
}
|
||
|
|
||
|
type FabricMeta struct {
|
||
|
Version int
|
||
|
Libraries FabricLibraries
|
||
|
MainClass map[string]string
|
||
|
}
|
||
|
|
||
|
type FabricVersion struct {
|
||
|
Loader FabricDefinition
|
||
|
Intermediary FabricDefinition
|
||
|
LauncherMeta FabricMeta
|
||
|
}
|
||
|
|
||
|
func (Fabric)GetFabricVersions(mcVersion string) ([]FabricVersion, error) {
|
||
|
resp, err := http.Get("https://meta.fabricmc.net/v2/versions/loader/"+mcVersion)
|
||
|
if err != nil {
|
||
|
return []FabricVersion{}, fmt.Errorf("Unable to pull fabric version manifest: %s\n", err)
|
||
|
}
|
||
|
defer resp.Body.Close()
|
||
|
data, _ := io.ReadAll(resp.Body)
|
||
|
versions := []FabricVersion{}
|
||
|
json.Unmarshal(data, &versions)
|
||
|
fmt.Printf("fabric versions found for %s: %+v\n", mcVersion, versions)
|
||
|
return versions, nil
|
||
|
}
|