hcloud-upload-image/hcloudimages/doc_test.go
Malthe Poulsen fcbc14aab6
feat: add --location flag to specify datacenter region (#141)
Allow users to specify which Hetzner datacenter location to use for the
temporary server during image upload. Defaults to fsn1 for backward
compatibility.

Available locations: fsn1, nbg1, hel1, ash, hil, sin

Implements: #142
2025-12-22 13:36:50 +01:00

34 lines
762 B
Go

package hcloudimages_test
import (
"context"
"fmt"
"net/url"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/apricote/hcloud-upload-image/hcloudimages"
)
func ExampleClient_Upload() {
client := hcloudimages.NewClient(
hcloud.NewClient(hcloud.WithToken("<your token>")),
)
imageURL, err := url.Parse("https://example.com/disk-image.raw.bz2")
if err != nil {
panic(err)
}
image, err := client.Upload(context.TODO(), hcloudimages.UploadOptions{
ImageURL: imageURL,
ImageCompression: hcloudimages.CompressionBZ2,
Architecture: hcloud.ArchitectureX86,
Location: &hcloud.Location{Name: "nbg1"}, // Optional: defaults to fsn1
})
if err != nil {
panic(err)
}
fmt.Printf("Uploaded Image: %d", image.ID)
}