Go to file
jolheiser 24f778e3bc
New module
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2022-01-07 14:16:35 -06:00
.gitignore Initial Commit 2020-08-13 15:14:25 -05:00
LICENSE Initial Commit 2020-08-13 15:14:25 -05:00
Makefile Initial Commit 2020-08-13 15:14:25 -05:00
README.md New module 2022-01-07 14:16:35 -06:00
ban.go Add POST options 2020-10-05 22:21:20 -05:00
client.go Add POST options 2020-10-05 22:21:20 -05:00
custom.go Add POST options 2020-10-05 22:21:20 -05:00
go.mod New module 2022-01-07 14:16:35 -06:00
go.sum Initial Commit 2020-08-13 15:14:25 -05:00
graphql.go Add POST options 2020-10-05 22:21:20 -05:00
ping.go Add POST options 2020-10-05 22:21:20 -05:00
player.go Add POST options 2020-10-05 22:21:20 -05:00
plugin.go Add POST options 2020-10-05 22:21:20 -05:00
tps.go Add POST options 2020-10-05 22:21:20 -05:00
world.go Add POST options 2020-10-05 22:21:20 -05:00

README.md

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