The package hrobot is a libary for the Hetzner Robot API. The public API documentation is available robot.your-server.de
Please note this is not an official Hetzner product, the author is not in any way affiliated with Hetzner use at own risk!
Hrobot is used for the Robot Interface (Dedicated Servers at Hetzner)
If you are looking for the Hetzner Cloud go library you can check out the official hcloud-go package maintained by Hetzner.
package main
import (
"context"
"fmt"
"os"
"log"
"github.com/floshodan/hrobot-go/hrobot"
)
func main() {
//export HETZNER_TOKEN=USERNAME:PASSWORD
client := hrobot.NewClient(hrobot.WithToken(os.Getenv("HETZNER_TOKEN")))
// get list of server
serverlist, _, err := client.Server.List(context.Background())
if err != nil {
log.Fatalf("error retrieving server list: %s\n", err)
}
fmt.Printf("%+v\n", serverlist[0])
// retriev information for specific server id
server, _, err := client.Server.GetServerById(context.Background(), "1337")
if err != nil {
log.Fatalf("error retrieving server: %s\n", err)
}
fmt.Printf("%+v\n", server)
}
To authenticate the client we can use two different inbuild methods:
- Use the WithBasicAuth method which takes in (username, password) as string parameters.
client := hrobot.WithBasicAuth(username, password)
- By "Token" eg as an environment variable:
client := hrobot.NewClient(hrobot.WithToken(os.Getenv("HETZNER_TOKEN")))
The "Token" has the following structure: "username:password".
To use the Token as an enviroment variable as in the example above you can export a variable: export HETZNER_TOKEN="username:password"
in your terminal.
To make it persitent on your system you can put the export command in your ~/.profile
file.