go-serverapi/README.md

65 lines
1.1 KiB
Markdown
Raw Normal View History

# go-serverapi
Go SDK for [ServerAPI](https://git.etztech.xyz/Minecraft/ServerAPI).
2020-08-13 20:41:14 +00:00
## Example
```go
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](LICENSE)