mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
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
34 lines
762 B
Go
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)
|
|
}
|