go-serverapi/ban.go

31 lines
716 B
Go

package serverapi
import (
"fmt"
"time"
)
// Ban is a Minecraft ban
type Ban struct {
Target string `json:"target"`
Source string `jso:"source"`
Reason string `json:"reason"`
Created int64 `json:"created"`
Expiration int64 `json:"expiration"`
}
// CreatedTime is Created converted to a time.Time
func (b *Ban) CreatedTime() time.Time {
return time.Unix(b.Created/1000, 0)
}
// ExpirationTime is Expiration converted to a time.Time
func (b *Ban) ExpirationTime() time.Time {
return time.Unix(b.Expiration/1000, 0)
}
// Bans gets a list of Ban from a ServerAPI instance
func (c *Client) Bans() (bans []*Ban, err error) {
return bans, c.json(fmt.Sprintf("%s/bans", c.Endpoint), &bans)
}