63 lines
996 B
Go
63 lines
996 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type Modpack struct {
|
||
|
Name string
|
||
|
Id string
|
||
|
Last_updated string
|
||
|
Versions []Version
|
||
|
}
|
||
|
|
||
|
type Version struct {
|
||
|
Version string
|
||
|
Data time.Time
|
||
|
File string
|
||
|
}
|
||
|
|
||
|
type ModpackManager struct {
|
||
|
app *App
|
||
|
Modpacks []Modpack
|
||
|
}
|
||
|
|
||
|
|
||
|
func (m *ModpackManager) QuerryModpacks() {
|
||
|
buff := new(bytes.Buffer)
|
||
|
err := HttpDownload("modpacks.json", buff, nil)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
err = json.Unmarshal(buff.Bytes(), &m.Modpacks)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for ind, pack := range m.Modpacks {
|
||
|
buff = new(bytes.Buffer)
|
||
|
err = HttpDownload(pack.Id + "/versions.json", buff, nil)
|
||
|
if err != nil {
|
||
|
continue
|
||
|
}
|
||
|
json.Unmarshal(buff.Bytes(), &pack.Versions)
|
||
|
m.Modpacks[ind] = pack
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
func (m *ModpackManager) GetModpacks() []Modpack{
|
||
|
return m.Modpacks
|
||
|
}
|
||
|
|
||
|
func (m *ModpackManager) GetModpack(id string) Modpack {
|
||
|
for _, pack := range m.Modpacks {
|
||
|
if pack.Id == id {
|
||
|
return pack
|
||
|
}
|
||
|
}
|
||
|
return Modpack{}
|
||
|
}
|