mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2025-08-06 22:06:58 +02:00
Some checks are pending
While adding support for qcow2 images in #69 I broke support for local images. Building a shell pipeline through string concatenation is not a good idea... The specific issue was fixed and I also moved building the shell pipeline to a separate function and added unit tests for all cases, so it should be easier to spot these issues in the future. Closes #97
34 lines
680 B
Go
34 lines
680 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,
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fmt.Printf("Uploaded Image: %d", image.ID)
|
|
}
|