61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
// App struct
|
|
type App struct {
|
|
ctx context.Context
|
|
}
|
|
|
|
type Modpack struct {
|
|
Name string
|
|
Nd string
|
|
Last_updated string
|
|
}
|
|
|
|
// NewApp creates a new App application struct
|
|
func NewApp() *App {
|
|
return &App{}
|
|
}
|
|
|
|
// startup is called when the app starts. The context is saved
|
|
// so we can call the runtime methods
|
|
func (a *App) startup(ctx context.Context) {
|
|
a.ctx = ctx
|
|
}
|
|
|
|
// Greet returns a greeting for the given name
|
|
func (a *App) Greet(name string) string {
|
|
return fmt.Sprintf("Hello %s, It's show time!", name)
|
|
}
|
|
|
|
func (a *App) GetModpacks() []string {
|
|
res, err := http.Get("https://gitea.piwalker.net/fclauncher/modpacks.json")
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
}
|
|
defer res.Body.Close()
|
|
body, err := io.ReadAll(res.Body)
|
|
var modpacks []Modpack
|
|
err = json.Unmarshal([]byte(body), &modpacks)
|
|
if err != nil {
|
|
fmt.Println(err.Error())
|
|
return nil
|
|
}
|
|
var names []string
|
|
for _, pack := range modpacks {
|
|
names = append(names, pack.Name)
|
|
}
|
|
return names
|
|
}
|
|
|
|
func (a *App) CheckPrerequisites() {
|
|
|
|
}
|