You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
jolheiser 24f778e3bc
New module
2 weeks ago
.gitignore Initial Commit 1 year ago
LICENSE Initial Commit 1 year ago
Makefile Initial Commit 1 year ago
README.md New module 2 weeks ago
ban.go Add POST options 1 year ago
client.go Add POST options 1 year ago
custom.go Add POST options 1 year ago
go.mod New module 2 weeks ago
go.sum Initial Commit 1 year ago
graphql.go Add POST options 1 year ago
ping.go Add POST options 1 year ago
player.go Add POST options 1 year ago
plugin.go Add POST options 1 year ago
tps.go Add POST options 1 year ago
world.go Add POST options 1 year ago

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