go-mcm/web/online.go

35 lines
579 B
Go

package web
import (
"encoding/json"
"fmt"
"go.etztech.xyz/go-mcm/internal"
)
type Online struct {
Query Query `json:"query"`
}
type Query struct {
Max string `json:"max"`
Online string `json:"online"`
Players []string `json:"players"`
}
func (web *Web) Online() (*Online, error) {
endpoint := fmt.Sprintf("%s?api=%s", web.endpoint("online"), web.Token)
online := &Online{}
resp, err := internal.ResponseGet(endpoint)
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &online)
if err != nil {
return nil, err
}
return online, nil
}