go-mcm/web/online.go

35 lines
579 B
Go
Raw Normal View History

2019-10-03 20:22:22 +00:00
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
}