2019-10-03 20:22:22 +00:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2020-06-11 06:10:01 +00:00
|
|
|
|
2019-10-03 20:22:22 +00:00
|
|
|
"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
|
|
|
|
}
|