serverapi

package module
v0.0.0-...-94e800d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 8 Imported by: 0

README

go-serverapi

Go SDK for ServerAPI.

Example

package main

import (
    "context"
    "fmt"
    "net/http"

    "go.etztech.xyz/go-serverapi"
)

func main() {
    // ServerAPI REST client
    client := serverapi.NewClient("https://api.server.com/", &serverapi.ClientOptions{
        HTTP:     http.DefaultClient,
        Password: "",
    })

    // Use the REST API
    players, err := client.Players()
    if err != nil {
        panic(err)
    }

    for _, p := range players {
        fmt.Println(p.Name)
    }

    fmt.Println()
    fmt.Println()

    // GraphQL Client
    g := client.GraphQL()
    r := client.GraphQLRequest(`
{
    players {
        name
    }
}
`)

    // Use the GraphQL API
    data := struct {
        // Uses serverapi.Players for the magic naming of JSON
        Players serverapi.Players
    }{}
    if err := g.Run(context.Background(), r, &data); err != nil {
        panic(err)
    }

    for _, p := range data.Players {
        fmt.Println(p.Name)
    }
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ban

type Ban struct {
	Kick
	Source  string `json:"source"`
	Created int64  `json:"created"`
}

Ban is a Minecraft ban

func (*Ban) CreatedTime

func (b *Ban) CreatedTime() time.Time

CreatedTime is Created converted to a time.Time

type Bans

type Bans []*Ban

Bans is a list of Ban

type Broadcast

type Broadcast struct {
	From    string `json:"from"`
	Message string `json:"message"`
}

Broadcast is a server-wide message

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client aimed at a specific ServerAPI endpoint

func NewClient

func NewClient(endpoint string, opts ...ClientOption) *Client

NewClient returns a new Client for making ServerAPI requests

func (*Client) Ban

func (c *Client) Ban(b Ban) (int, error)

Ban bans a player

func (*Client) Bans

func (c *Client) Bans() (bans Ban, err error)

Bans gets a list of Ban from a ServerAPI instance

func (*Client) Broadcast

func (c *Client) Broadcast(b Broadcast) (int, error)

Broadcast sends a message to the server

func (*Client) Custom

func (c *Client) Custom(cu Custom) (int, error)

Custom sends a custom command to the server

func (*Client) GraphQL

func (c *Client) GraphQL() *gql.Client

GraphQL returns a gql.Client for a ServerAPI instance

func (*Client) GraphQLRequest

func (c *Client) GraphQLRequest(query string) *gql.Request

GraphQLRequest returns a pre-filled gql.Request with the password set

func (*Client) Kick

func (c *Client) Kick(k Kick) (int, error)

Kick kicks a player

func (*Client) Ping

func (c *Client) Ping() (ping *Ping, err error)

Ping returns a Ping

func (*Client) Players

func (c *Client) Players() (players Players, err error)

Players returns a list of Player from a ServerAPI instance

func (*Client) Plugins

func (c *Client) Plugins() (plugins Plugins, err error)

Plugins returns a list of Plugin from a ServerAPI instance

func (*Client) TPS

func (c *Client) TPS() (tps *TPS, err error)

TPS returns TPS from a ServerAPI instance

func (*Client) TempBan

func (c *Client) TempBan(t TempBan) (int, error)

TempBan temporarily bans a player

func (*Client) Unban

func (c *Client) Unban(u Unban) (int, error)

Unban pardons a player

func (*Client) World

func (c *Client) World(name string) (world *World, err error)

World returns a single World from a ServerAPI instance

func (*Client) Worlds

func (c *Client) Worlds() (worlds Worlds, err error)

Worlds returns a list of World from a ServerAPI instance

type ClientOption

type ClientOption func(c *Client)

ClientOption is options for a Client

func WithHTTP

func WithHTTP(http *http.Client) ClientOption

WithHTTP is a ClientOption for setting the http.Client of a Client

func WithToken

func WithToken(token string) ClientOption

WithToken is a ClientOption for setting the token of a Client

type Custom

type Custom struct {
	Command string   `json:"command"`
	Args    []string `json:"args"`
}

Custom is for edge-cases

type Kick

type Kick struct {
	Unban
	Reason string `json:"reason"`
}

Kick is a Minecraft kick

type Ping

type Ping struct {
	CurrentPlayers int    `json:"current_players"`
	MaxPlayers     int    `json:"max_players"`
	Type           string `json:"type"`
	Version        string `json:"version"`
	MOTD           string `json:"motd"`
}

Ping is a Minecraft ping query

type Player

type Player struct {
	Name string `json:"name"`
	UUID string `json:"uuid"`
}

Player is a Minecraft player

type Players

type Players []*Player

Players is a list of Player

type Plugin

type Plugin struct {
	Name    string   `json:"name"`
	Version string   `json:"version"`
	Website string   `json:"website"`
	Authors []string `json:"authors"`
}

Plugin is a Minecraft plugin

type Plugins

type Plugins []*Plugin

Plugins is a list of Plugin

type TPS

type TPS struct {
	Average float64   `json:"average"`
	History []float64 `json:"history"`
}

TPS is a Minecraft server's relative performance

type TempBan

type TempBan struct {
	Ban
	Expiration int64 `json:"expiration"`
}

Ban is a Minecraft ban with an expiration

func (*TempBan) ExpirationTime

func (t *TempBan) ExpirationTime() time.Time

ExpirationTime is Expiration converted to a time.Time

type Unban

type Unban struct {
	Target string `json:"target"`
}

Unban is a Minecraft pardon

type Weather

type Weather int

Weather described the weather of a Minecraft World

const (
	// Clear weather
	WeatherClear Weather = iota
	// Raining/Snowing
	WeatherStorm
	// Thundering
	WeatherThunder
)

func (Weather) String

func (w Weather) String() string

String is human-friendly Weather

type World

type World struct {
	Name     string  `json:"name"`
	Weather  Weather `json:"weather"`
	Time     int64   `json:"time"`
	FullTime int64   `json:"full_time"`
}

World is a Minecraft world

func (*World) FullTimeHours

func (w *World) FullTimeHours() int64

FullTimeHours returns FullTime in hours

func (*World) TimeHours

func (w *World) TimeHours() int64

TimeHours returns Time in hours

type Worlds

type Worlds []*World

Worlds is a list of World

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL