Skip to main content

Go SDK

The github.com/ariaservice/arianet-go module is the official Go client for the Arianet APIs. It uses only the Go standard library and needs Go 1.22 or newer.

Install​

go get github.com/ariaservice/arianet-go@v0.1.0

Quickstart​

Create a personal API token in the panel and export it:

export ARIANET_TOKEN="paste-your-token-here"
package main

import (
"context"
"fmt"
"log"

"github.com/ariaservice/arianet-go"
)

func main() {
ctx := context.Background()
client := arianet.NewClient("") // empty token: read ARIANET_TOKEN

resp, err := client.Cloud.ListServers(ctx, &arianet.CloudListServersParams{
PerPage: arianet.Int(50),
})
if err != nil {
log.Fatal(err)
}

var servers []struct {
ID int64 `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
if err := resp.DecodeData(&servers); err != nil {
log.Fatal(err)
}
for _, s := range servers {
fmt.Println(s.ID, s.Name, s.Status)
}
}

API groups​

Each API is a field of Client:

FieldAPI
client.CoreAccount, tokens, VPS, SSH keys, firewalls, balance and invoices
client.CloudArianet Cloud
client.RegionalVPSRegional VPS
client.HostingHosting
client.BaremetalDedicated servers
client.SMSSMS

Path parameters are method arguments, the JSON request body is body any (a struct, a map or json.RawMessage), and query parameters are an optional <Group><Method>Params struct with pointer fields (use arianet.String, arianet.Int, arianet.Bool). Every method returns *arianet.Response; read the whole body with Decode or its data member with DecodeData.

resp, err := client.Cloud.CreateServer(ctx, map[string]any{
"name": "web-1",
"plan_id": 101,
"image": "ubuntu-24.04",
"datacenter": "ovh",
})

Configuration​

client := arianet.NewClient(token,
arianet.WithBaseURL("https://api.ariaservice.net"), // default, or $ARIANET_API_URL
arianet.WithMaxRetries(3),
arianet.WithMaxRetryWait(60*time.Second),
arianet.WithHTTPClient(&http.Client{Timeout: 30 * time.Second}),
)

WithMaxRetries sets the number of retries (default 3) and WithMaxRetryWait the longest wait before one retry (default 60 seconds). A 429 whose Retry-After is longer is returned at once. To keep a retried order safe across process restarts too, send your own key with arianet.WithIdempotencyKey(key).

Errors​

_, err := client.Core.CreateServer(ctx, order)
var apiErr *arianet.APIError
switch {
case arianet.HasCode(err, arianet.ErrorCodeInsufficientBalance):
// top up the wallet
case errors.As(err, &apiErr):
log.Printf("HTTP %d %s: %s", apiErr.StatusCode, apiErr.Code, apiErr.Message)
case err != nil:
log.Fatal(err) // *arianet.ConnectionError or a context error
}

APIError.Code is the stable error code in lower case, and Reason refines it on some errors (for example identity_hold). The helpers IsNotFound, IsUnauthorized, IsForbidden and IsRateLimited are available too.

Regions and new endpoints​

iran := client.RegionalVPS.WithRegion("iran-1")
resp, err := iran.ListServers(ctx)

// Any path, with the same auth, retries and errors:
resp, err = client.Do(ctx, "GET", "/cloud/v1/new-endpoint", nil, nil)