This is the unofficial Go implementation of this I'm still learning so expect badly design code PR are appreciated.
Code Inspiration: https://github.com/bwmarrin/discordgo
The exaroton API allows automated access to some basic functionalities of your game servers, such as starting or stopping the server. You can read the API documentation here: https://developers.exaroton.com
go get github.com/Jiternos/exaroton
To use the API and this client you have to get your API key, which you can generate in your exaroton account settings: https://exaroton.com/account
Import the package into your project.
import "github.com/Jiternos/exaroton"
Construct a new client.
exaroton := exaroton.New(envToken)
Remember to keep your token secret and don't add it to any private or public code repositories.
client := exaroton.New(envToken)
account, err := client.Account()
if err != nil {
log.Error(err)
return
}
fmt.Printf("My account is %s and I have %d credits", account.Name, account.Credits)
The account object contains the fields and information as listed in the documentation.
servers, err := client.Servers()
if err != nil {
log.Error(err)
return
}
for _, s := range servers {
fmt.Println(s.Name + ": " + s.ID)
}
Each server object contains the fields and information as listed in the documentation.
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
fmt.Println(server.Name)
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
fmt.Prinln(server.GetStatus())
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
err = server.Start(client)
if err != nil {
log.Error(err)
return
}
err = server.Stop(client)
if err != nil {
log.Error(err)
return
}
err = server.Restart(client)
if err != nil {
log.Error(err)
return
}
It's important to catch errors, because incorrect calls, e.g. a server.Stop()
when the server is offline will result in an error.
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
err := server.ExecuteCommand(client, "say hello")
if err != nil {
log.Error(err)
return
}
client, err := exaroton.New(envToken)
if err != nil {
log.Error(err)
return
}
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
logs, err := server.GetLogs(client)
if err != nil {
log.Error(err)
return
}
fmt.Println(logs)
This is cached and will not return the latest updates immediately. It's also not possible to get the server logs while the server is loading, stopping or saving.
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
logs, err := server.ShareLogs(client)
if err != nil {
log.Error(err)
return
}
fmt.Println(logs.ID)
fmt.Println(logs.Raw)
fmt.Println(logs.URL)
This is cached and will not return the latest updates immediately. It's also not possible to share the server logs while the server is loading, stopping or saving.
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
err = server.SetMOTD(client, "Hello World!")
if err != nil {
log.Error(err)
return
}
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
ram, err := server.GetRam(client)
if err != nil {
log.Error(err)
return
}
fmt.Println(ram)
The amount of RAM is returned in full GiB.
server, err := client.Server(id)
if err != nil {
log.Error(err)
return
}
err = server.SetRam(client, 2)
if err != nil {
log.Error(err)
return
}
The RAM is set in full GiB and has to be between 2 and 16.
A player list is a list of players such as the whitelist, ops or bans. Player list entries are usually usernames, but might be something else, e.g. IPs in the banned-ips list. All player list operations are storage operations that might take a while, so try to reduce the amount of requests and combine actions when possible (e.g. adding/deleting multiple entries at once). Player lists are also cached any might not immediately return new results when changed through other methods e.g. in-game.
You can list all available player lists...
playerList, err := server.GetPlayerList(client)
if err != nil {
log.Error(err)
return
}
fmt.Println(playerList.List)
playerList, err := server.GetPlayerList(client, "whitelist")
if err != nil {
log.Error(err)
return
}
We handle all the heavy work of adding player list entries for you, e.g. automatically adding UUIDs depending on the online mode or executing the necessary commands while the server is running.
playerList, err := server.GetPlayerList(client, "whitelist")
if err != nil {
log.Error(err)
return
}
username := []string{"a", "b", "c", "d"}
playerList.AddEntry(client, username)
playerList, err := server.GetPlayerList(client, "whitelist")
if err != nil {
log.Error(err)
return
}
username := []string{"a", "b", "c", "d"}
playerList.RemoveEntry(client, username)
The websocket API allows a constant connection to our websocket service to receive events in real time without polling (e.g. trying to get the server status every few seconds).