From f40c0ce633574aa650fa4013511bbf5415dfdbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20T=C3=B6lle?= Date: Wed, 5 Jul 2023 12:27:20 +0200 Subject: [PATCH] feat!: use int64 for ID fields The `int` datatype is not guaranteed to offer 64 bits of precision. On 32-bit platforms it only has 32 bits of precision. This is incompatible with the Hetzner Cloud identifiers having up to 52-bits after September 1st 2023. See #263 for more details about this change. --- README.md | 31 +++++++++++++-- hcloud/action.go | 14 +++---- hcloud/action_test.go | 2 +- hcloud/certificate.go | 10 ++--- hcloud/certificate_test.go | 2 +- hcloud/client.go | 4 +- hcloud/client_test.go | 2 +- hcloud/datacenter.go | 10 ++--- hcloud/datacenter_test.go | 2 +- hcloud/firewall.go | 10 ++--- hcloud/firewall_test.go | 2 +- hcloud/floating_ip.go | 8 ++-- hcloud/floating_ip_test.go | 2 +- hcloud/hcloud_test.go | 2 +- hcloud/image.go | 12 +++--- hcloud/image_test.go | 2 +- hcloud/iso.go | 10 ++--- hcloud/iso_test.go | 2 +- hcloud/load_balancer.go | 8 ++-- hcloud/load_balancer_test.go | 2 +- hcloud/load_balancer_type.go | 10 ++--- hcloud/load_balancer_type_test.go | 2 +- hcloud/location.go | 10 ++--- hcloud/location_test.go | 2 +- hcloud/metadata/client.go | 6 +-- hcloud/network.go | 12 +++--- hcloud/network_test.go | 2 +- hcloud/placement_group.go | 12 +++--- hcloud/placement_group_test.go | 2 +- hcloud/pricing.go | 2 +- hcloud/pricing_test.go | 2 +- hcloud/primary_ip.go | 24 ++++++------ hcloud/primary_ip_test.go | 2 +- hcloud/rdns_test.go | 2 +- hcloud/resource.go | 2 +- hcloud/schema.go | 10 ++--- hcloud/schema/action.go | 4 +- hcloud/schema/certificate.go | 4 +- hcloud/schema/datacenter.go | 6 +-- hcloud/schema/firewall.go | 4 +- hcloud/schema/floating_ip.go | 8 ++-- hcloud/schema/image.go | 6 +-- hcloud/schema/iso.go | 2 +- hcloud/schema/load_balancer.go | 58 ++++++++++++++--------------- hcloud/schema/load_balancer_type.go | 2 +- hcloud/schema/location.go | 2 +- hcloud/schema/network.go | 8 ++-- hcloud/schema/placement_group.go | 4 +- hcloud/schema/pricing.go | 4 +- hcloud/schema/primary_ip.go | 4 +- hcloud/schema/server.go | 42 ++++++++++----------- hcloud/schema/server_type.go | 2 +- hcloud/schema/ssh_key.go | 2 +- hcloud/schema/volume.go | 8 ++-- hcloud/schema_test.go | 14 +++---- hcloud/server.go | 18 ++++----- hcloud/server_test.go | 2 +- hcloud/server_type.go | 10 ++--- hcloud/server_type_test.go | 2 +- hcloud/ssh_key.go | 10 ++--- hcloud/ssh_key_test.go | 2 +- hcloud/volume.go | 10 ++--- hcloud/volume_test.go | 2 +- 63 files changed, 252 insertions(+), 227 deletions(-) diff --git a/README.md b/README.md index 238c6ecef..ae763fae1 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # hcloud: A Go library for the Hetzner Cloud API [![GitHub Actions status](https://github.com/hetznercloud/hcloud-go/workflows/Continuous%20Integration/badge.svg)](https://github.com/hetznercloud/hcloud-go/actions) -[![GoDoc](https://godoc.org/github.com/hetznercloud/hcloud-go/hcloud?status.svg)](https://godoc.org/github.com/hetznercloud/hcloud-go/hcloud) +[![Go Reference](https://pkg.go.dev/badge/github.com/hetznercloud/hcloud-go/v2/hcloud.svg)](https://pkg.go.dev/github.com/hetznercloud/hcloud-go/v2/hcloud) Package hcloud is a library for the Hetzner Cloud API. -The library’s documentation is available at [GoDoc](https://godoc.org/github.com/hetznercloud/hcloud-go/hcloud), +The library’s documentation is available at [pkg.go.dev](https://godoc.org/github.com/hetznercloud/hcloud-go/v2/hcloud), the public API documentation is available at [docs.hetzner.cloud](https://docs.hetzner.cloud/). ## Example @@ -18,7 +18,7 @@ import ( "fmt" "log" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) func main() { @@ -36,6 +36,31 @@ func main() { } ``` +## Upgrading + +### Support + +- `v2` is actively maintained by Hetzner Cloud +- `v1` is supported until September 1st 2023 and will continue to receive new features until then. See [#263](https://github.com/hetznercloud/hcloud-go/issues/263). + +### From v1 to v2 + +Version 2.0.0 was published because we changed the datatype of all `ID` fields from `int` to `int64`. + +To migrate to the new version, replace all your imports to reference the new module path: + +```diff + import ( +- "github.com/hetznercloud/hcloud-go/v2/hcloud" ++ "github.com/hetznercloud/hcloud-go/v2/hcloud" + ) +``` + +When you compile your code, it will show any invalid usages of `int` in your code that you need to fix. We commonly found these changes while updating our integrations: + +- `strconv.Atoi(idString)` (parsing integers) needs to be replaced by `strconv.ParseInt(idString, 10, 64)` +- `strconv.Itoa(id)` (formatting integers) needs to be replaced by `strconv.FormatInt(id, 10)` + ## Go Version Support The library supports the latest two Go minor versions, e.g. at the time Go 1.19 is released, it supports Go 1.18 and 1.19. diff --git a/hcloud/action.go b/hcloud/action.go index 9040215ca..c9c0a3b6b 100644 --- a/hcloud/action.go +++ b/hcloud/action.go @@ -6,12 +6,12 @@ import ( "net/url" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Action represents an action in the Hetzner Cloud. type Action struct { - ID int + ID int64 Status ActionStatus Command string Progress int @@ -34,7 +34,7 @@ const ( // ActionResource references other resources from an action. type ActionResource struct { - ID int + ID int64 Type ActionResourceType } @@ -76,7 +76,7 @@ type ActionClient struct { } // GetByID retrieves an action by its ID. If the action does not exist, nil is returned. -func (c *ActionClient) GetByID(ctx context.Context, id int) (*Action, *Response, error) { +func (c *ActionClient) GetByID(ctx context.Context, id int64) (*Action, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/actions/%d", id), nil) if err != nil { return nil, nil, err @@ -96,7 +96,7 @@ func (c *ActionClient) GetByID(ctx context.Context, id int) (*Action, *Response, // ActionListOpts specifies options for listing actions. type ActionListOpts struct { ListOpts - ID []int + ID []int64 Status []ActionStatus Sort []string } @@ -189,8 +189,8 @@ func (c *ActionClient) WatchOverallProgress(ctx context.Context, actions []*Acti defer close(errCh) defer close(progressCh) - successIDs := make([]int, 0, len(actions)) - watchIDs := make(map[int]struct{}, len(actions)) + successIDs := make([]int64, 0, len(actions)) + watchIDs := make(map[int64]struct{}, len(actions)) for _, action := range actions { watchIDs[action.ID] = struct{}{} } diff --git a/hcloud/action_test.go b/hcloud/action_test.go index 660f3ded1..f19f26a0d 100644 --- a/hcloud/action_test.go +++ b/hcloud/action_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestActionClientGetByID(t *testing.T) { diff --git a/hcloud/certificate.go b/hcloud/certificate.go index 39a93e64b..909739f9f 100644 --- a/hcloud/certificate.go +++ b/hcloud/certificate.go @@ -10,7 +10,7 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // CertificateType is the type of available certificate types. @@ -50,7 +50,7 @@ const ( // CertificateUsedByRef points to a resource that uses this certificate. type CertificateUsedByRef struct { - ID int + ID int64 Type CertificateUsedByRefType } @@ -70,7 +70,7 @@ func (st *CertificateStatus) IsFailed() bool { // Certificate represents a certificate in the Hetzner Cloud. type Certificate struct { - ID int + ID int64 Name string Labels map[string]string Type CertificateType @@ -96,7 +96,7 @@ type CertificateClient struct { } // GetByID retrieves a Certificate by its ID. If the Certificate does not exist, nil is returned. -func (c *CertificateClient) GetByID(ctx context.Context, id int) (*Certificate, *Response, error) { +func (c *CertificateClient) GetByID(ctx context.Context, id int64) (*Certificate, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/certificates/%d", id), nil) if err != nil { return nil, nil, err @@ -128,7 +128,7 @@ func (c *CertificateClient) GetByName(ctx context.Context, name string) (*Certif // Get retrieves a Certificate by its ID if the input can be parsed as an integer, otherwise it // retrieves a Certificate by its name. If the Certificate does not exist, nil is returned. func (c *CertificateClient) Get(ctx context.Context, idOrName string) (*Certificate, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) diff --git a/hcloud/certificate_test.go b/hcloud/certificate_test.go index 003bcb5e2..8bc11d329 100644 --- a/hcloud/certificate_test.go +++ b/hcloud/certificate_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestCertificateCreateOptsValidate_Uploaded(t *testing.T) { diff --git a/hcloud/client.go b/hcloud/client.go index f3b5a833f..7af025769 100644 --- a/hcloud/client.go +++ b/hcloud/client.go @@ -18,8 +18,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "golang.org/x/net/http/httpguts" - "github.com/hetznercloud/hcloud-go/hcloud/internal/instrumentation" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/internal/instrumentation" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Endpoint is the base URL of the API. diff --git a/hcloud/client_test.go b/hcloud/client_test.go index e4df032ec..36164cb79 100644 --- a/hcloud/client_test.go +++ b/hcloud/client_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) type testEnv struct { diff --git a/hcloud/datacenter.go b/hcloud/datacenter.go index 369ac9418..77a4de067 100644 --- a/hcloud/datacenter.go +++ b/hcloud/datacenter.go @@ -6,12 +6,12 @@ import ( "net/url" "strconv" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Datacenter represents a datacenter in the Hetzner Cloud. type Datacenter struct { - ID int + ID int64 Name string Description string Location *Location @@ -30,7 +30,7 @@ type DatacenterClient struct { } // GetByID retrieves a datacenter by its ID. If the datacenter does not exist, nil is returned. -func (c *DatacenterClient) GetByID(ctx context.Context, id int) (*Datacenter, *Response, error) { +func (c *DatacenterClient) GetByID(ctx context.Context, id int64) (*Datacenter, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/datacenters/%d", id), nil) if err != nil { return nil, nil, err @@ -62,8 +62,8 @@ func (c *DatacenterClient) GetByName(ctx context.Context, name string) (*Datacen // Get retrieves a datacenter by its ID if the input can be parsed as an integer, otherwise it // retrieves a datacenter by its name. If the datacenter does not exist, nil is returned. func (c *DatacenterClient) Get(ctx context.Context, idOrName string) (*Datacenter, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/datacenter_test.go b/hcloud/datacenter_test.go index c258f370f..253efe51a 100644 --- a/hcloud/datacenter_test.go +++ b/hcloud/datacenter_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestDatacenterClient(t *testing.T) { diff --git a/hcloud/firewall.go b/hcloud/firewall.go index 70dd3ac7e..71cc90a26 100644 --- a/hcloud/firewall.go +++ b/hcloud/firewall.go @@ -11,12 +11,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Firewall represents a Firewall in the Hetzner Cloud. type Firewall struct { - ID int + ID int64 Name string Labels map[string]string Created time.Time @@ -80,7 +80,7 @@ type FirewallResource struct { // FirewallResourceServer represents a Server to apply a Firewall on. type FirewallResourceServer struct { - ID int + ID int64 } // FirewallResourceLabelSelector represents a LabelSelector to apply a Firewall on. @@ -94,7 +94,7 @@ type FirewallClient struct { } // GetByID retrieves a Firewall by its ID. If the Firewall does not exist, nil is returned. -func (c *FirewallClient) GetByID(ctx context.Context, id int) (*Firewall, *Response, error) { +func (c *FirewallClient) GetByID(ctx context.Context, id int64) (*Firewall, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/firewalls/%d", id), nil) if err != nil { return nil, nil, err @@ -126,7 +126,7 @@ func (c *FirewallClient) GetByName(ctx context.Context, name string) (*Firewall, // Get retrieves a Firewall by its ID if the input can be parsed as an integer, otherwise it // retrieves a Firewall by its name. If the Firewall does not exist, nil is returned. func (c *FirewallClient) Get(ctx context.Context, idOrName string) (*Firewall, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) diff --git a/hcloud/firewall_test.go b/hcloud/firewall_test.go index 335314808..296747902 100644 --- a/hcloud/firewall_test.go +++ b/hcloud/firewall_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestFirewallCreateOptsValidate(t *testing.T) { diff --git a/hcloud/floating_ip.go b/hcloud/floating_ip.go index 2974a5e9b..4163150eb 100644 --- a/hcloud/floating_ip.go +++ b/hcloud/floating_ip.go @@ -11,12 +11,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // FloatingIP represents a Floating IP in the Hetzner Cloud. type FloatingIP struct { - ID int + ID int64 Description string Created time.Time IP net.IP @@ -95,7 +95,7 @@ type FloatingIPClient struct { // GetByID retrieves a Floating IP by its ID. If the Floating IP does not exist, // nil is returned. -func (c *FloatingIPClient) GetByID(ctx context.Context, id int) (*FloatingIP, *Response, error) { +func (c *FloatingIPClient) GetByID(ctx context.Context, id int64) (*FloatingIP, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/floating_ips/%d", id), nil) if err != nil { return nil, nil, err @@ -127,7 +127,7 @@ func (c *FloatingIPClient) GetByName(ctx context.Context, name string) (*Floatin // Get retrieves a Floating IP by its ID if the input can be parsed as an integer, otherwise it // retrieves a Floating IP by its name. If the Floating IP does not exist, nil is returned. func (c *FloatingIPClient) Get(ctx context.Context, idOrName string) (*FloatingIP, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) diff --git a/hcloud/floating_ip_test.go b/hcloud/floating_ip_test.go index b3494a18d..4f6d1efe4 100644 --- a/hcloud/floating_ip_test.go +++ b/hcloud/floating_ip_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestFloatingIPClientGetByID(t *testing.T) { diff --git a/hcloud/hcloud_test.go b/hcloud/hcloud_test.go index 4f7f7cb0a..855d948f8 100644 --- a/hcloud/hcloud_test.go +++ b/hcloud/hcloud_test.go @@ -5,7 +5,7 @@ import ( "fmt" "log" - "github.com/hetznercloud/hcloud-go/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud" ) func Example() { diff --git a/hcloud/image.go b/hcloud/image.go index 04d61b50c..2e48b84d6 100644 --- a/hcloud/image.go +++ b/hcloud/image.go @@ -9,12 +9,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Image represents an Image in the Hetzner Cloud. type Image struct { - ID int + ID int64 Name string Type ImageType Status ImageStatus @@ -81,7 +81,7 @@ type ImageClient struct { } // GetByID retrieves an image by its ID. If the image does not exist, nil is returned. -func (c *ImageClient) GetByID(ctx context.Context, id int) (*Image, *Response, error) { +func (c *ImageClient) GetByID(ctx context.Context, id int64) (*Image, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/images/%d", id), nil) if err != nil { return nil, nil, err @@ -132,7 +132,7 @@ func (c *ImageClient) GetByNameAndArchitecture(ctx context.Context, name string, // // Deprecated: Use [ImageClient.GetForArchitecture] instead. func (c *ImageClient) Get(ctx context.Context, idOrName string) (*Image, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) @@ -144,7 +144,7 @@ func (c *ImageClient) Get(ctx context.Context, idOrName string) (*Image, *Respon // In contrast to [ImageClient.Get], this method also returns deprecated images. Depending on your needs you should // check for this in your calling method. func (c *ImageClient) GetForArchitecture(ctx context.Context, idOrName string, architecture Architecture) (*Image, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByNameAndArchitecture(ctx, idOrName, architecture) @@ -168,7 +168,7 @@ func (l ImageListOpts) values() url.Values { vals.Add("type", string(typ)) } if l.BoundTo != nil { - vals.Add("bound_to", strconv.Itoa(l.BoundTo.ID)) + vals.Add("bound_to", strconv.FormatInt(l.BoundTo.ID, 10)) } if l.Name != "" { vals.Add("name", l.Name) diff --git a/hcloud/image_test.go b/hcloud/image_test.go index 745552ba7..31707baff 100644 --- a/hcloud/image_test.go +++ b/hcloud/image_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestImageIsDeprecated(t *testing.T) { diff --git a/hcloud/iso.go b/hcloud/iso.go index 5b015eaa7..52d3e0e87 100644 --- a/hcloud/iso.go +++ b/hcloud/iso.go @@ -7,12 +7,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // ISO represents an ISO image in the Hetzner Cloud. type ISO struct { - ID int + ID int64 Name string Description string Type ISOType @@ -42,7 +42,7 @@ type ISOClient struct { } // GetByID retrieves an ISO by its ID. -func (c *ISOClient) GetByID(ctx context.Context, id int) (*ISO, *Response, error) { +func (c *ISOClient) GetByID(ctx context.Context, id int64) (*ISO, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/isos/%d", id), nil) if err != nil { return nil, nil, err @@ -73,8 +73,8 @@ func (c *ISOClient) GetByName(ctx context.Context, name string) (*ISO, *Response // Get retrieves an ISO by its ID if the input can be parsed as an integer, otherwise it retrieves an ISO by its name. func (c *ISOClient) Get(ctx context.Context, idOrName string) (*ISO, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/iso_test.go b/hcloud/iso_test.go index 1d010a7ce..7e507f733 100644 --- a/hcloud/iso_test.go +++ b/hcloud/iso_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestISOIsDeprecated(t *testing.T) { diff --git a/hcloud/load_balancer.go b/hcloud/load_balancer.go index 6d4311b08..d2b657929 100644 --- a/hcloud/load_balancer.go +++ b/hcloud/load_balancer.go @@ -11,12 +11,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // LoadBalancer represents a Load Balancer in the Hetzner Cloud. type LoadBalancer struct { - ID int + ID int64 Name string PublicNet LoadBalancerPublicNet PrivateNet []LoadBalancerPrivateNet @@ -241,7 +241,7 @@ type LoadBalancerClient struct { } // GetByID retrieves a Load Balancer by its ID. If the Load Balancer does not exist, nil is returned. -func (c *LoadBalancerClient) GetByID(ctx context.Context, id int) (*LoadBalancer, *Response, error) { +func (c *LoadBalancerClient) GetByID(ctx context.Context, id int64) (*LoadBalancer, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/load_balancers/%d", id), nil) if err != nil { return nil, nil, err @@ -273,7 +273,7 @@ func (c *LoadBalancerClient) GetByName(ctx context.Context, name string) (*LoadB // Get retrieves a Load Balancer by its ID if the input can be parsed as an integer, otherwise it // retrieves a Load Balancer by its name. If the Load Balancer does not exist, nil is returned. func (c *LoadBalancerClient) Get(ctx context.Context, idOrName string) (*LoadBalancer, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) diff --git a/hcloud/load_balancer_test.go b/hcloud/load_balancer_test.go index 1cadfc885..f9190b26b 100644 --- a/hcloud/load_balancer_test.go +++ b/hcloud/load_balancer_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestLoadBalancerClientGetByID(t *testing.T) { diff --git a/hcloud/load_balancer_type.go b/hcloud/load_balancer_type.go index 348d4bf38..61bac6b86 100644 --- a/hcloud/load_balancer_type.go +++ b/hcloud/load_balancer_type.go @@ -6,12 +6,12 @@ import ( "net/url" "strconv" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // LoadBalancerType represents a LoadBalancer type in the Hetzner Cloud. type LoadBalancerType struct { - ID int + ID int64 Name string Description string MaxConnections int @@ -27,7 +27,7 @@ type LoadBalancerTypeClient struct { } // GetByID retrieves a Load Balancer type by its ID. If the Load Balancer type does not exist, nil is returned. -func (c *LoadBalancerTypeClient) GetByID(ctx context.Context, id int) (*LoadBalancerType, *Response, error) { +func (c *LoadBalancerTypeClient) GetByID(ctx context.Context, id int64) (*LoadBalancerType, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/load_balancer_types/%d", id), nil) if err != nil { return nil, nil, err @@ -59,8 +59,8 @@ func (c *LoadBalancerTypeClient) GetByName(ctx context.Context, name string) (*L // Get retrieves a Load Balancer type by its ID if the input can be parsed as an integer, otherwise it // retrieves a Load Balancer type by its name. If the Load Balancer type does not exist, nil is returned. func (c *LoadBalancerTypeClient) Get(ctx context.Context, idOrName string) (*LoadBalancerType, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/load_balancer_type_test.go b/hcloud/load_balancer_type_test.go index 7f4610fa7..6815f5659 100644 --- a/hcloud/load_balancer_type_test.go +++ b/hcloud/load_balancer_type_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestLoadBalancerTypeClient(t *testing.T) { diff --git a/hcloud/location.go b/hcloud/location.go index 9577830d7..4a57127ca 100644 --- a/hcloud/location.go +++ b/hcloud/location.go @@ -6,12 +6,12 @@ import ( "net/url" "strconv" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Location represents a location in the Hetzner Cloud. type Location struct { - ID int + ID int64 Name string Description string Country string @@ -27,7 +27,7 @@ type LocationClient struct { } // GetByID retrieves a location by its ID. If the location does not exist, nil is returned. -func (c *LocationClient) GetByID(ctx context.Context, id int) (*Location, *Response, error) { +func (c *LocationClient) GetByID(ctx context.Context, id int64) (*Location, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/locations/%d", id), nil) if err != nil { return nil, nil, err @@ -59,8 +59,8 @@ func (c *LocationClient) GetByName(ctx context.Context, name string) (*Location, // Get retrieves a location by its ID if the input can be parsed as an integer, otherwise it // retrieves a location by its name. If the location does not exist, nil is returned. func (c *LocationClient) Get(ctx context.Context, idOrName string) (*Location, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/location_test.go b/hcloud/location_test.go index 4f6d7fb69..ada52f95f 100644 --- a/hcloud/location_test.go +++ b/hcloud/location_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestLocationClient(t *testing.T) { diff --git a/hcloud/metadata/client.go b/hcloud/metadata/client.go index 4c173d757..67f902c57 100644 --- a/hcloud/metadata/client.go +++ b/hcloud/metadata/client.go @@ -10,7 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus" - "github.com/hetznercloud/hcloud-go/hcloud/internal/instrumentation" + "github.com/hetznercloud/hcloud-go/v2/hcloud/internal/instrumentation" ) const Endpoint = "http://169.254.169.254/hetzner/v1/metadata" @@ -104,12 +104,12 @@ func (c *Client) Hostname() (string, error) { } // InstanceID returns the ID of the server that did the request to the Metadata server. -func (c *Client) InstanceID() (int, error) { +func (c *Client) InstanceID() (int64, error) { resp, err := c.get("/instance-id") if err != nil { return 0, err } - return strconv.Atoi(resp) + return strconv.ParseInt(resp, 10, 64) } // PublicIPv4 returns the Public IPv4 of the server that did the request to the Metadata server. diff --git a/hcloud/network.go b/hcloud/network.go index cf85a5546..c92097d98 100644 --- a/hcloud/network.go +++ b/hcloud/network.go @@ -11,7 +11,7 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // NetworkZone specifies a network zone. @@ -36,7 +36,7 @@ const ( // Network represents a network in the Hetzner Cloud. type Network struct { - ID int + ID int64 Name string Created time.Time IPRange *net.IPNet @@ -56,7 +56,7 @@ type NetworkSubnet struct { IPRange *net.IPNet NetworkZone NetworkZone Gateway net.IP - VSwitchID int + VSwitchID int64 } // NetworkRoute represents a route of a network. @@ -76,7 +76,7 @@ type NetworkClient struct { } // GetByID retrieves a network by its ID. If the network does not exist, nil is returned. -func (c *NetworkClient) GetByID(ctx context.Context, id int) (*Network, *Response, error) { +func (c *NetworkClient) GetByID(ctx context.Context, id int64) (*Network, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/networks/%d", id), nil) if err != nil { return nil, nil, err @@ -108,8 +108,8 @@ func (c *NetworkClient) GetByName(ctx context.Context, name string) (*Network, * // Get retrieves a network by its ID if the input can be parsed as an integer, otherwise it // retrieves a network by its name. If the network does not exist, nil is returned. func (c *NetworkClient) Get(ctx context.Context, idOrName string) (*Network, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/network_test.go b/hcloud/network_test.go index b06f33463..51f1fe8ef 100644 --- a/hcloud/network_test.go +++ b/hcloud/network_test.go @@ -7,7 +7,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestNetworkClientGetByID(t *testing.T) { diff --git a/hcloud/placement_group.go b/hcloud/placement_group.go index 07fedad5e..2b3a41b4f 100644 --- a/hcloud/placement_group.go +++ b/hcloud/placement_group.go @@ -10,16 +10,16 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // PlacementGroup represents a Placement Group in the Hetzner Cloud. type PlacementGroup struct { - ID int + ID int64 Name string Labels map[string]string Created time.Time - Servers []int + Servers []int64 Type PlacementGroupType } @@ -37,7 +37,7 @@ type PlacementGroupClient struct { } // GetByID retrieves a PlacementGroup by its ID. If the PlacementGroup does not exist, nil is returned. -func (c *PlacementGroupClient) GetByID(ctx context.Context, id int) (*PlacementGroup, *Response, error) { +func (c *PlacementGroupClient) GetByID(ctx context.Context, id int64) (*PlacementGroup, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/placement_groups/%d", id), nil) if err != nil { return nil, nil, err @@ -69,8 +69,8 @@ func (c *PlacementGroupClient) GetByName(ctx context.Context, name string) (*Pla // Get retrieves a PlacementGroup by its ID if the input can be parsed as an integer, otherwise it // retrieves a PlacementGroup by its name. If the PlacementGroup does not exist, nil is returned. func (c *PlacementGroupClient) Get(ctx context.Context, idOrName string) (*PlacementGroup, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/placement_group_test.go b/hcloud/placement_group_test.go index fd2caeda7..0b37f49ff 100644 --- a/hcloud/placement_group_test.go +++ b/hcloud/placement_group_test.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestPlacementGroupClientGetByID(t *testing.T) { diff --git a/hcloud/pricing.go b/hcloud/pricing.go index 836f391ff..2a1b96b76 100644 --- a/hcloud/pricing.go +++ b/hcloud/pricing.go @@ -3,7 +3,7 @@ package hcloud import ( "context" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Pricing specifies pricing information for various resources. diff --git a/hcloud/pricing_test.go b/hcloud/pricing_test.go index f85ee9974..d6668aa83 100644 --- a/hcloud/pricing_test.go +++ b/hcloud/pricing_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestPricingClientGet(t *testing.T) { diff --git a/hcloud/primary_ip.go b/hcloud/primary_ip.go index c478241d1..532e0e6c3 100644 --- a/hcloud/primary_ip.go +++ b/hcloud/primary_ip.go @@ -10,12 +10,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // PrimaryIP defines a Primary IP. type PrimaryIP struct { - ID int + ID int64 IP net.IP Network *net.IPNet Labels map[string]string @@ -23,7 +23,7 @@ type PrimaryIP struct { Type PrimaryIPType Protection PrimaryIPProtection DNSPtr map[string]string - AssigneeID int + AssigneeID int64 AssigneeType string AutoDelete bool Blocked bool @@ -92,7 +92,7 @@ const ( // PrimaryIPCreateOpts defines the request to // create a Primary IP. type PrimaryIPCreateOpts struct { - AssigneeID *int `json:"assignee_id,omitempty"` + AssigneeID *int64 `json:"assignee_id,omitempty"` AssigneeType string `json:"assignee_type"` AutoDelete *bool `json:"auto_delete,omitempty"` Datacenter string `json:"datacenter,omitempty"` @@ -119,8 +119,8 @@ type PrimaryIPUpdateOpts struct { // PrimaryIPAssignOpts defines the request to // assign a Primary IP to an assignee (usually a server). type PrimaryIPAssignOpts struct { - ID int - AssigneeID int `json:"assignee_id"` + ID int64 + AssigneeID int64 `json:"assignee_id"` AssigneeType string `json:"assignee_type"` } @@ -133,7 +133,7 @@ type PrimaryIPAssignResult struct { // PrimaryIPChangeDNSPtrOpts defines the request to // change a DNS PTR entry from a Primary IP. type PrimaryIPChangeDNSPtrOpts struct { - ID int + ID int64 DNSPtr string `json:"dns_ptr"` IP string `json:"ip"` } @@ -147,7 +147,7 @@ type PrimaryIPChangeDNSPtrResult struct { // PrimaryIPChangeProtectionOpts defines the request to // change protection configuration of a Primary IP. type PrimaryIPChangeProtectionOpts struct { - ID int + ID int64 Delete bool `json:"delete"` } @@ -163,7 +163,7 @@ type PrimaryIPClient struct { } // GetByID retrieves a Primary IP by its ID. If the Primary IP does not exist, nil is returned. -func (c *PrimaryIPClient) GetByID(ctx context.Context, id int) (*PrimaryIP, *Response, error) { +func (c *PrimaryIPClient) GetByID(ctx context.Context, id int64) (*PrimaryIP, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/primary_ips/%d", id), nil) if err != nil { return nil, nil, err @@ -207,8 +207,8 @@ func (c *PrimaryIPClient) GetByName(ctx context.Context, name string) (*PrimaryI // Get retrieves a Primary IP by its ID if the input can be parsed as an integer, otherwise it // retrieves a Primary IP by its name. If the Primary IP does not exist, nil is returned. func (c *PrimaryIPClient) Get(ctx context.Context, idOrName string) (*PrimaryIP, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } @@ -363,7 +363,7 @@ func (c *PrimaryIPClient) Assign(ctx context.Context, opts PrimaryIPAssignOpts) } // Unassign a Primary IP from a resource. -func (c *PrimaryIPClient) Unassign(ctx context.Context, id int) (*Action, *Response, error) { +func (c *PrimaryIPClient) Unassign(ctx context.Context, id int64) (*Action, *Response, error) { path := fmt.Sprintf("/primary_ips/%d/actions/unassign", id) req, err := c.client.NewRequest(ctx, "POST", path, bytes.NewReader([]byte{})) if err != nil { diff --git a/hcloud/primary_ip_test.go b/hcloud/primary_ip_test.go index d368b71a4..e53c93658 100644 --- a/hcloud/primary_ip_test.go +++ b/hcloud/primary_ip_test.go @@ -10,7 +10,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestPrimaryIPClient(t *testing.T) { diff --git a/hcloud/rdns_test.go b/hcloud/rdns_test.go index dc15b9e0a..355bec63c 100644 --- a/hcloud/rdns_test.go +++ b/hcloud/rdns_test.go @@ -7,7 +7,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestChangeDNSPtr(t *testing.T) { diff --git a/hcloud/resource.go b/hcloud/resource.go index 8a734dfd6..a74b2cf7a 100644 --- a/hcloud/resource.go +++ b/hcloud/resource.go @@ -2,6 +2,6 @@ package hcloud // Resource defines the schema of a resource. type Resource struct { - ID int + ID int64 Type string } diff --git a/hcloud/schema.go b/hcloud/schema.go index f4a93667a..bdd5a54e7 100644 --- a/hcloud/schema.go +++ b/hcloud/schema.go @@ -6,7 +6,7 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // This file provides converter functions to convert models in the @@ -893,7 +893,7 @@ func loadBalancerCreateOptsToSchema(opts LoadBalancerCreateOpts) schema.LoadBala } if opts.Location != nil { if opts.Location.ID != 0 { - req.Location = Ptr(strconv.Itoa(opts.Location.ID)) + req.Location = Ptr(strconv.FormatInt(opts.Location.ID, 10)) } else { req.Location = Ptr(opts.Location.Name) } @@ -943,7 +943,7 @@ func loadBalancerCreateOptsToSchema(opts LoadBalancerCreateOpts) schema.LoadBala } } if service.HTTP.Certificates != nil { - certificates := []int{} + certificates := []int64{} for _, certificate := range service.HTTP.Certificates { certificates = append(certificates, certificate.ID) } @@ -998,7 +998,7 @@ func loadBalancerAddServiceOptsToSchema(opts LoadBalancerAddServiceOpts) schema. req.HTTP.CookieLifetime = Ptr(int(opts.HTTP.CookieLifetime.Seconds())) } if opts.HTTP.Certificates != nil { - certificates := []int{} + certificates := []int64{} for _, certificate := range opts.HTTP.Certificates { certificates = append(certificates, certificate.ID) } @@ -1050,7 +1050,7 @@ func loadBalancerUpdateServiceOptsToSchema(opts LoadBalancerUpdateServiceOpts) s req.HTTP.CookieLifetime = Ptr(int(opts.HTTP.CookieLifetime.Seconds())) } if opts.HTTP.Certificates != nil { - certificates := []int{} + certificates := []int64{} for _, certificate := range opts.HTTP.Certificates { certificates = append(certificates, certificate.ID) } diff --git a/hcloud/schema/action.go b/hcloud/schema/action.go index df4d7cf71..49ac96a22 100644 --- a/hcloud/schema/action.go +++ b/hcloud/schema/action.go @@ -4,7 +4,7 @@ import "time" // Action defines the schema of an action. type Action struct { - ID int `json:"id"` + ID int64 `json:"id"` Status string `json:"status"` Command string `json:"command"` Progress int `json:"progress"` @@ -16,7 +16,7 @@ type Action struct { // ActionResourceReference defines the schema of an action resource reference. type ActionResourceReference struct { - ID int `json:"id"` + ID int64 `json:"id"` Type string `json:"type"` } diff --git a/hcloud/schema/certificate.go b/hcloud/schema/certificate.go index a81b807a2..eb7b03ce2 100644 --- a/hcloud/schema/certificate.go +++ b/hcloud/schema/certificate.go @@ -4,7 +4,7 @@ import "time" // CertificateUsedByRef defines the schema of a resource using a certificate. type CertificateUsedByRef struct { - ID int `json:"id"` + ID int64 `json:"id"` Type string `json:"type"` } @@ -16,7 +16,7 @@ type CertificateStatusRef struct { // Certificate defines the schema of an certificate. type Certificate struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Labels map[string]string `json:"labels"` Type string `json:"type"` diff --git a/hcloud/schema/datacenter.go b/hcloud/schema/datacenter.go index 3e8178e89..eaa12429f 100644 --- a/hcloud/schema/datacenter.go +++ b/hcloud/schema/datacenter.go @@ -2,13 +2,13 @@ package schema // Datacenter defines the schema of a datacenter. type Datacenter struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` Location Location `json:"location"` ServerTypes struct { - Supported []int `json:"supported"` - Available []int `json:"available"` + Supported []int64 `json:"supported"` + Available []int64 `json:"available"` } `json:"server_types"` } diff --git a/hcloud/schema/firewall.go b/hcloud/schema/firewall.go index b085bbb13..371e648f1 100644 --- a/hcloud/schema/firewall.go +++ b/hcloud/schema/firewall.go @@ -4,7 +4,7 @@ import "time" // Firewall defines the schema of a Firewall. type Firewall struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Labels map[string]string `json:"labels"` Created time.Time `json:"created"` @@ -54,7 +54,7 @@ type FirewallResourceLabelSelector struct { // FirewallResourceServer defines the schema of a Server to apply a Firewall on. type FirewallResourceServer struct { - ID int `json:"id"` + ID int64 `json:"id"` } // FirewallCreateResponse defines the schema of the response when creating a Firewall. diff --git a/hcloud/schema/floating_ip.go b/hcloud/schema/floating_ip.go index 37295dad9..6256b0d96 100644 --- a/hcloud/schema/floating_ip.go +++ b/hcloud/schema/floating_ip.go @@ -4,12 +4,12 @@ import "time" // FloatingIP defines the schema of a Floating IP. type FloatingIP struct { - ID int `json:"id"` + ID int64 `json:"id"` Description *string `json:"description"` Created time.Time `json:"created"` IP string `json:"ip"` Type string `json:"type"` - Server *int `json:"server"` + Server *int64 `json:"server"` DNSPtr []FloatingIPDNSPtr `json:"dns_ptr"` HomeLocation Location `json:"home_location"` Blocked bool `json:"blocked"` @@ -59,7 +59,7 @@ type FloatingIPListResponse struct { type FloatingIPCreateRequest struct { Type string `json:"type"` HomeLocation *string `json:"home_location,omitempty"` - Server *int `json:"server,omitempty"` + Server *int64 `json:"server,omitempty"` Description *string `json:"description,omitempty"` Labels *map[string]string `json:"labels,omitempty"` Name *string `json:"name,omitempty"` @@ -75,7 +75,7 @@ type FloatingIPCreateResponse struct { // FloatingIPActionAssignRequest defines the schema of the request to // create an assign Floating IP action. type FloatingIPActionAssignRequest struct { - Server int `json:"server"` + Server int64 `json:"server"` } // FloatingIPActionAssignResponse defines the schema of the response when diff --git a/hcloud/schema/image.go b/hcloud/schema/image.go index 76775b131..1520935ec 100644 --- a/hcloud/schema/image.go +++ b/hcloud/schema/image.go @@ -4,7 +4,7 @@ import "time" // Image defines the schema of an image. type Image struct { - ID int `json:"id"` + ID int64 `json:"id"` Status string `json:"status"` Type string `json:"type"` Name *string `json:"name"` @@ -13,7 +13,7 @@ type Image struct { DiskSize float32 `json:"disk_size"` Created time.Time `json:"created"` CreatedFrom *ImageCreatedFrom `json:"created_from"` - BoundTo *int `json:"bound_to"` + BoundTo *int64 `json:"bound_to"` OSFlavor string `json:"os_flavor"` OSVersion *string `json:"os_version"` Architecture string `json:"architecture"` @@ -31,7 +31,7 @@ type ImageProtection struct { // ImageCreatedFrom defines the schema of the images created from reference. type ImageCreatedFrom struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` } diff --git a/hcloud/schema/iso.go b/hcloud/schema/iso.go index dfcc4e347..4f89dd046 100644 --- a/hcloud/schema/iso.go +++ b/hcloud/schema/iso.go @@ -4,7 +4,7 @@ import "time" // ISO defines the schema of an ISO image. type ISO struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` Type string `json:"type"` diff --git a/hcloud/schema/load_balancer.go b/hcloud/schema/load_balancer.go index 68adf5eb6..7e1c4f5da 100644 --- a/hcloud/schema/load_balancer.go +++ b/hcloud/schema/load_balancer.go @@ -3,7 +3,7 @@ package schema import "time" type LoadBalancer struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` PublicNet LoadBalancerPublicNet `json:"public_net"` PrivateNet []LoadBalancerPrivateNet `json:"private_net"` @@ -37,7 +37,7 @@ type LoadBalancerPublicNetIPv6 struct { } type LoadBalancerPrivateNet struct { - Network int `json:"network"` + Network int64 `json:"network"` IP string `json:"ip"` } @@ -59,11 +59,11 @@ type LoadBalancerService struct { } type LoadBalancerServiceHTTP struct { - CookieName string `json:"cookie_name"` - CookieLifetime int `json:"cookie_lifetime"` - Certificates []int `json:"certificates"` - RedirectHTTP bool `json:"redirect_http"` - StickySessions bool `json:"sticky_sessions"` + CookieName string `json:"cookie_name"` + CookieLifetime int `json:"cookie_lifetime"` + Certificates []int64 `json:"certificates"` + RedirectHTTP bool `json:"redirect_http"` + StickySessions bool `json:"sticky_sessions"` } type LoadBalancerServiceHealthCheck struct { @@ -99,7 +99,7 @@ type LoadBalancerTargetHealthStatus struct { } type LoadBalancerTargetServer struct { - ID int `json:"id"` + ID int64 `json:"id"` } type LoadBalancerTargetLabelSelector struct { @@ -127,7 +127,7 @@ type LoadBalancerActionAddTargetRequest struct { } type LoadBalancerActionAddTargetRequestServer struct { - ID int `json:"id"` + ID int64 `json:"id"` } type LoadBalancerActionAddTargetRequestLabelSelector struct { @@ -150,7 +150,7 @@ type LoadBalancerActionRemoveTargetRequest struct { } type LoadBalancerActionRemoveTargetRequestServer struct { - ID int `json:"id"` + ID int64 `json:"id"` } type LoadBalancerActionRemoveTargetRequestLabelSelector struct { @@ -175,11 +175,11 @@ type LoadBalancerActionAddServiceRequest struct { } type LoadBalancerActionAddServiceRequestHTTP struct { - CookieName *string `json:"cookie_name,omitempty"` - CookieLifetime *int `json:"cookie_lifetime,omitempty"` - Certificates *[]int `json:"certificates,omitempty"` - RedirectHTTP *bool `json:"redirect_http,omitempty"` - StickySessions *bool `json:"sticky_sessions,omitempty"` + CookieName *string `json:"cookie_name,omitempty"` + CookieLifetime *int `json:"cookie_lifetime,omitempty"` + Certificates *[]int64 `json:"certificates,omitempty"` + RedirectHTTP *bool `json:"redirect_http,omitempty"` + StickySessions *bool `json:"sticky_sessions,omitempty"` } type LoadBalancerActionAddServiceRequestHealthCheck struct { @@ -213,11 +213,11 @@ type LoadBalancerActionUpdateServiceRequest struct { } type LoadBalancerActionUpdateServiceRequestHTTP struct { - CookieName *string `json:"cookie_name,omitempty"` - CookieLifetime *int `json:"cookie_lifetime,omitempty"` - Certificates *[]int `json:"certificates,omitempty"` - RedirectHTTP *bool `json:"redirect_http,omitempty"` - StickySessions *bool `json:"sticky_sessions,omitempty"` + CookieName *string `json:"cookie_name,omitempty"` + CookieLifetime *int `json:"cookie_lifetime,omitempty"` + Certificates *[]int64 `json:"certificates,omitempty"` + RedirectHTTP *bool `json:"redirect_http,omitempty"` + StickySessions *bool `json:"sticky_sessions,omitempty"` } type LoadBalancerActionUpdateServiceRequestHealthCheck struct { @@ -259,7 +259,7 @@ type LoadBalancerCreateRequest struct { Targets []LoadBalancerCreateRequestTarget `json:"targets,omitempty"` Services []LoadBalancerCreateRequestService `json:"services,omitempty"` PublicInterface *bool `json:"public_interface,omitempty"` - Network *int `json:"network,omitempty"` + Network *int64 `json:"network,omitempty"` } type LoadBalancerCreateRequestAlgorithm struct { @@ -275,7 +275,7 @@ type LoadBalancerCreateRequestTarget struct { } type LoadBalancerCreateRequestTargetServer struct { - ID int `json:"id"` + ID int64 `json:"id"` } type LoadBalancerCreateRequestTargetLabelSelector struct { @@ -296,11 +296,11 @@ type LoadBalancerCreateRequestService struct { } type LoadBalancerCreateRequestServiceHTTP struct { - CookieName *string `json:"cookie_name,omitempty"` - CookieLifetime *int `json:"cookie_lifetime,omitempty"` - Certificates *[]int `json:"certificates,omitempty"` - RedirectHTTP *bool `json:"redirect_http,omitempty"` - StickySessions *bool `json:"sticky_sessions,omitempty"` + CookieName *string `json:"cookie_name,omitempty"` + CookieLifetime *int `json:"cookie_lifetime,omitempty"` + Certificates *[]int64 `json:"certificates,omitempty"` + RedirectHTTP *bool `json:"redirect_http,omitempty"` + StickySessions *bool `json:"sticky_sessions,omitempty"` } type LoadBalancerCreateRequestServiceHealthCheck struct { @@ -351,7 +351,7 @@ type LoadBalancerActionChangeAlgorithmResponse struct { } type LoadBalancerActionAttachToNetworkRequest struct { - Network int `json:"network"` + Network int64 `json:"network"` IP *string `json:"ip,omitempty"` } @@ -360,7 +360,7 @@ type LoadBalancerActionAttachToNetworkResponse struct { } type LoadBalancerActionDetachFromNetworkRequest struct { - Network int `json:"network"` + Network int64 `json:"network"` } type LoadBalancerActionDetachFromNetworkResponse struct { diff --git a/hcloud/schema/load_balancer_type.go b/hcloud/schema/load_balancer_type.go index b0baf0489..09ac43d7a 100644 --- a/hcloud/schema/load_balancer_type.go +++ b/hcloud/schema/load_balancer_type.go @@ -2,7 +2,7 @@ package schema // LoadBalancerType defines the schema of a LoadBalancer type. type LoadBalancerType struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` MaxConnections int `json:"max_connections"` diff --git a/hcloud/schema/location.go b/hcloud/schema/location.go index 3dd58ad5e..e07306071 100644 --- a/hcloud/schema/location.go +++ b/hcloud/schema/location.go @@ -2,7 +2,7 @@ package schema // Location defines the schema of a location. type Location struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` Country string `json:"country"` diff --git a/hcloud/schema/network.go b/hcloud/schema/network.go index 56bcbea9c..2344aea45 100644 --- a/hcloud/schema/network.go +++ b/hcloud/schema/network.go @@ -4,13 +4,13 @@ import "time" // Network defines the schema of a network. type Network struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Created time.Time `json:"created"` IPRange string `json:"ip_range"` Subnets []NetworkSubnet `json:"subnets"` Routes []NetworkRoute `json:"routes"` - Servers []int `json:"servers"` + Servers []int64 `json:"servers"` Protection NetworkProtection `json:"protection"` Labels map[string]string `json:"labels"` ExposeRoutesToVSwitch bool `json:"expose_routes_to_vswitch"` @@ -22,7 +22,7 @@ type NetworkSubnet struct { IPRange string `json:"ip_range"` NetworkZone string `json:"network_zone"` Gateway string `json:"gateway,omitempty"` - VSwitchID int `json:"vswitch_id,omitempty"` + VSwitchID int64 `json:"vswitch_id,omitempty"` } // NetworkRoute represents a route of a network. @@ -95,7 +95,7 @@ type NetworkActionAddSubnetRequest struct { IPRange string `json:"ip_range,omitempty"` NetworkZone string `json:"network_zone"` Gateway string `json:"gateway"` - VSwitchID int `json:"vswitch_id,omitempty"` + VSwitchID int64 `json:"vswitch_id,omitempty"` } // NetworkActionAddSubnetResponse defines the schema of the response when diff --git a/hcloud/schema/placement_group.go b/hcloud/schema/placement_group.go index 6bee4390c..671bd6bed 100644 --- a/hcloud/schema/placement_group.go +++ b/hcloud/schema/placement_group.go @@ -3,11 +3,11 @@ package schema import "time" type PlacementGroup struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Labels map[string]string `json:"labels"` Created time.Time `json:"created"` - Servers []int `json:"servers"` + Servers []int64 `json:"servers"` Type string `json:"type"` } diff --git a/hcloud/schema/pricing.go b/hcloud/schema/pricing.go index 0c06c73d2..192352f5d 100644 --- a/hcloud/schema/pricing.go +++ b/hcloud/schema/pricing.go @@ -61,7 +61,7 @@ type PricingServerBackup struct { // PricingServerType defines the schema of pricing information for a server type. type PricingServerType struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Prices []PricingServerTypePrice `json:"prices"` } @@ -76,7 +76,7 @@ type PricingServerTypePrice struct { // PricingLoadBalancerType defines the schema of pricing information for a Load Balancer type. type PricingLoadBalancerType struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Prices []PricingLoadBalancerTypePrice `json:"prices"` } diff --git a/hcloud/schema/primary_ip.go b/hcloud/schema/primary_ip.go index f6c7229a2..b685c386f 100644 --- a/hcloud/schema/primary_ip.go +++ b/hcloud/schema/primary_ip.go @@ -4,14 +4,14 @@ import "time" // PrimaryIP defines a Primary IP. type PrimaryIP struct { - ID int `json:"id"` + ID int64 `json:"id"` IP string `json:"ip"` Labels map[string]string `json:"labels"` Name string `json:"name"` Type string `json:"type"` Protection PrimaryIPProtection `json:"protection"` DNSPtr []PrimaryIPDNSPTR `json:"dns_ptr"` - AssigneeID int `json:"assignee_id"` + AssigneeID int64 `json:"assignee_id"` AssigneeType string `json:"assignee_type"` AutoDelete bool `json:"auto_delete"` Blocked bool `json:"blocked"` diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go index 4786b1f9a..39a10b064 100644 --- a/hcloud/schema/server.go +++ b/hcloud/schema/server.go @@ -4,7 +4,7 @@ import "time" // Server defines the schema of a server. type Server struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Status string `json:"status"` Created time.Time `json:"created"` @@ -22,7 +22,7 @@ type Server struct { Image *Image `json:"image"` Protection ServerProtection `json:"protection"` Labels map[string]string `json:"labels"` - Volumes []int `json:"volumes"` + Volumes []int64 `json:"volumes"` PrimaryDiskSize int `json:"primary_disk_size"` PlacementGroup *PlacementGroup `json:"placement_group"` } @@ -38,14 +38,14 @@ type ServerProtection struct { type ServerPublicNet struct { IPv4 ServerPublicNetIPv4 `json:"ipv4"` IPv6 ServerPublicNetIPv6 `json:"ipv6"` - FloatingIPs []int `json:"floating_ips"` + FloatingIPs []int64 `json:"floating_ips"` Firewalls []ServerFirewall `json:"firewalls"` } // ServerPublicNetIPv4 defines the schema of a server's public // network information for an IPv4. type ServerPublicNetIPv4 struct { - ID int `json:"id"` + ID int64 `json:"id"` IP string `json:"ip"` Blocked bool `json:"blocked"` DNSPtr string `json:"dns_ptr"` @@ -54,7 +54,7 @@ type ServerPublicNetIPv4 struct { // ServerPublicNetIPv6 defines the schema of a server's public // network information for an IPv6. type ServerPublicNetIPv6 struct { - ID int `json:"id"` + ID int64 `json:"id"` IP string `json:"ip"` Blocked bool `json:"blocked"` DNSPtr []ServerPublicNetIPv6DNSPtr `json:"dns_ptr"` @@ -70,13 +70,13 @@ type ServerPublicNetIPv6DNSPtr struct { // ServerFirewall defines the schema of a Server's Firewalls on // a certain network interface. type ServerFirewall struct { - ID int `json:"id"` + ID int64 `json:"id"` Status string `json:"status"` } // ServerPrivateNet defines the schema of a server's private network information. type ServerPrivateNet struct { - Network int `json:"network"` + Network int64 `json:"network"` IP string `json:"ip"` AliasIPs []string `json:"alias_ips"` MACAddress string `json:"mac_address"` @@ -100,31 +100,31 @@ type ServerCreateRequest struct { Name string `json:"name"` ServerType interface{} `json:"server_type"` // int or string Image interface{} `json:"image"` // int or string - SSHKeys []int `json:"ssh_keys,omitempty"` + SSHKeys []int64 `json:"ssh_keys,omitempty"` Location string `json:"location,omitempty"` Datacenter string `json:"datacenter,omitempty"` UserData string `json:"user_data,omitempty"` StartAfterCreate *bool `json:"start_after_create,omitempty"` Labels *map[string]string `json:"labels,omitempty"` Automount *bool `json:"automount,omitempty"` - Volumes []int `json:"volumes,omitempty"` - Networks []int `json:"networks,omitempty"` + Volumes []int64 `json:"volumes,omitempty"` + Networks []int64 `json:"networks,omitempty"` Firewalls []ServerCreateFirewalls `json:"firewalls,omitempty"` - PlacementGroup int `json:"placement_group,omitempty"` + PlacementGroup int64 `json:"placement_group,omitempty"` PublicNet *ServerCreatePublicNet `json:"public_net,omitempty"` } // ServerCreatePublicNet defines the public network configuration of a server. type ServerCreatePublicNet struct { - EnableIPv4 bool `json:"enable_ipv4"` - EnableIPv6 bool `json:"enable_ipv6"` - IPv4ID int `json:"ipv4,omitempty"` - IPv6ID int `json:"ipv6,omitempty"` + EnableIPv4 bool `json:"enable_ipv4"` + EnableIPv6 bool `json:"enable_ipv6"` + IPv4ID int64 `json:"ipv4,omitempty"` + IPv6ID int64 `json:"ipv6,omitempty"` } // ServerCreateFirewalls defines which Firewalls to apply when creating a Server. type ServerCreateFirewalls struct { - Firewall int `json:"firewall"` + Firewall int64 `json:"firewall"` } // ServerCreateResponse defines the schema of the response when @@ -233,7 +233,7 @@ type ServerActionCreateImageResponse struct { // create a enable_rescue server action. type ServerActionEnableRescueRequest struct { Type *string `json:"type,omitempty"` - SSHKeys []int `json:"ssh_keys,omitempty"` + SSHKeys []int64 `json:"ssh_keys,omitempty"` } // ServerActionEnableRescueResponse defines the schema of the response when @@ -364,7 +364,7 @@ type ServerActionRequestConsoleResponse struct { // ServerActionAttachToNetworkRequest defines the schema for the request to // attach a network to a server. type ServerActionAttachToNetworkRequest struct { - Network int `json:"network"` + Network int64 `json:"network"` IP *string `json:"ip,omitempty"` AliasIPs []*string `json:"alias_ips,omitempty"` } @@ -378,7 +378,7 @@ type ServerActionAttachToNetworkResponse struct { // ServerActionDetachFromNetworkRequest defines the schema for the request to // detach a network from a server. type ServerActionDetachFromNetworkRequest struct { - Network int `json:"network"` + Network int64 `json:"network"` } // ServerActionDetachFromNetworkResponse defines the schema of the response when @@ -390,7 +390,7 @@ type ServerActionDetachFromNetworkResponse struct { // ServerActionChangeAliasIPsRequest defines the schema for the request to // change a server's alias IPs in a network. type ServerActionChangeAliasIPsRequest struct { - Network int `json:"network"` + Network int64 `json:"network"` AliasIPs []string `json:"alias_ips"` } @@ -419,7 +419,7 @@ type ServerTimeSeriesVals struct { // ServerActionAddToPlacementGroupRequest defines the schema for the request to // add a server to a placement group. type ServerActionAddToPlacementGroupRequest struct { - PlacementGroup int `json:"placement_group"` + PlacementGroup int64 `json:"placement_group"` } // ServerActionAddToPlacementGroupResponse defines the schema of the response when diff --git a/hcloud/schema/server_type.go b/hcloud/schema/server_type.go index e4d9b3a8a..0920a5ee1 100644 --- a/hcloud/schema/server_type.go +++ b/hcloud/schema/server_type.go @@ -2,7 +2,7 @@ package schema // ServerType defines the schema of a server type. type ServerType struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` Cores int `json:"cores"` diff --git a/hcloud/schema/ssh_key.go b/hcloud/schema/ssh_key.go index f230b3ddd..7e095bc5a 100644 --- a/hcloud/schema/ssh_key.go +++ b/hcloud/schema/ssh_key.go @@ -4,7 +4,7 @@ import "time" // SSHKey defines the schema of a SSH key. type SSHKey struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` Fingerprint string `json:"fingerprint"` PublicKey string `json:"public_key"` diff --git a/hcloud/schema/volume.go b/hcloud/schema/volume.go index ad745ea97..0dd391bcc 100644 --- a/hcloud/schema/volume.go +++ b/hcloud/schema/volume.go @@ -4,9 +4,9 @@ import "time" // Volume defines the schema of a volume. type Volume struct { - ID int `json:"id"` + ID int64 `json:"id"` Name string `json:"name"` - Server *int `json:"server"` + Server *int64 `json:"server"` Status string `json:"status"` Location Location `json:"location"` Size int `json:"size"` @@ -21,7 +21,7 @@ type Volume struct { type VolumeCreateRequest struct { Name string `json:"name"` Size int `json:"size"` - Server *int `json:"server,omitempty"` + Server *int64 `json:"server,omitempty"` Location interface{} `json:"location,omitempty"` // int, string, or nil Labels *map[string]string `json:"labels,omitempty"` Automount *bool `json:"automount,omitempty"` @@ -79,7 +79,7 @@ type VolumeActionChangeProtectionResponse struct { // VolumeActionAttachVolumeRequest defines the schema of the request to // attach a volume to a server. type VolumeActionAttachVolumeRequest struct { - Server int `json:"server"` + Server int64 `json:"server"` Automount *bool `json:"automount,omitempty"` } diff --git a/hcloud/schema_test.go b/hcloud/schema_test.go index e5ac9b2f8..667f72cf3 100644 --- a/hcloud/schema_test.go +++ b/hcloud/schema_test.go @@ -8,7 +8,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestActionFromSchema(t *testing.T) { @@ -2429,7 +2429,7 @@ func TestLoadBalancerCreateOptsToSchema(t *testing.T) { return &labels }(), PublicInterface: Ptr(true), - Network: Ptr(3), + Network: Ptr(int64(3)), Services: []schema.LoadBalancerCreateRequestService{ { Protocol: string(LoadBalancerServiceProtocolHTTP), @@ -2440,7 +2440,7 @@ func TestLoadBalancerCreateOptsToSchema(t *testing.T) { CookieLifetime: Ptr(5 * 60), RedirectHTTP: Ptr(true), StickySessions: Ptr(true), - Certificates: Ptr([]int{1, 2}), + Certificates: Ptr([]int64{1, 2}), }, HealthCheck: &schema.LoadBalancerCreateRequestServiceHealthCheck{ Protocol: string(LoadBalancerServiceProtocolHTTP), @@ -2535,7 +2535,7 @@ func TestLoadBalancerAddServiceOptsToSchema(t *testing.T) { CookieLifetime: Ptr(5 * 60), RedirectHTTP: Ptr(true), StickySessions: Ptr(true), - Certificates: Ptr([]int{1, 2}), + Certificates: Ptr([]int64{1, 2}), }, HealthCheck: &schema.LoadBalancerActionAddServiceRequestHealthCheck{ Protocol: string(LoadBalancerServiceProtocolHTTP), @@ -2575,7 +2575,7 @@ func TestLoadBalancerAddServiceOptsToSchema(t *testing.T) { CookieLifetime: Ptr(5 * 60), RedirectHTTP: Ptr(true), StickySessions: Ptr(true), - Certificates: Ptr([]int{1, 2}), + Certificates: Ptr([]int64{1, 2}), }, HealthCheck: nil, }, @@ -2637,7 +2637,7 @@ func TestLoadBalancerUpdateServiceOptsToSchema(t *testing.T) { CookieLifetime: Ptr(5 * 60), RedirectHTTP: Ptr(true), StickySessions: Ptr(true), - Certificates: Ptr([]int{1, 2}), + Certificates: Ptr([]int64{1, 2}), }, HealthCheck: &schema.LoadBalancerActionUpdateServiceRequestHealthCheck{ Protocol: Ptr(string(LoadBalancerServiceProtocolHTTP)), @@ -2677,7 +2677,7 @@ func TestLoadBalancerUpdateServiceOptsToSchema(t *testing.T) { CookieLifetime: Ptr(5 * 60), RedirectHTTP: Ptr(true), StickySessions: Ptr(true), - Certificates: Ptr([]int{1, 2}), + Certificates: Ptr([]int64{1, 2}), }, HealthCheck: nil, }, diff --git a/hcloud/server.go b/hcloud/server.go index 52ea7fa5c..477b686ee 100644 --- a/hcloud/server.go +++ b/hcloud/server.go @@ -12,12 +12,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Server represents a server in the Hetzner Cloud. type Server struct { - ID int + ID int64 Name string Status ServerStatus Created time.Time @@ -98,7 +98,7 @@ type ServerPublicNet struct { // ServerPublicNetIPv4 represents a server's public IPv4 address. type ServerPublicNetIPv4 struct { - ID int + ID int64 IP net.IP Blocked bool DNSPtr string @@ -110,7 +110,7 @@ func (n *ServerPublicNetIPv4) IsUnspecified() bool { // ServerPublicNetIPv6 represents a Server's public IPv6 network and address. type ServerPublicNetIPv6 struct { - ID int + ID int64 IP net.IP Network *net.IPNet Blocked bool @@ -194,7 +194,7 @@ type ServerClient struct { } // GetByID retrieves a server by its ID. If the server does not exist, nil is returned. -func (c *ServerClient) GetByID(ctx context.Context, id int) (*Server, *Response, error) { +func (c *ServerClient) GetByID(ctx context.Context, id int64) (*Server, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/servers/%d", id), nil) if err != nil { return nil, nil, err @@ -226,8 +226,8 @@ func (c *ServerClient) GetByName(ctx context.Context, name string) (*Server, *Re // Get retrieves a server by its ID if the input can be parsed as an integer, otherwise it // retrieves a server by its name. If the server does not exist, nil is returned. func (c *ServerClient) Get(ctx context.Context, idOrName string) (*Server, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } @@ -417,14 +417,14 @@ func (c *ServerClient) Create(ctx context.Context, opts ServerCreateOpts) (Serve } if opts.Location != nil { if opts.Location.ID != 0 { - reqBody.Location = strconv.Itoa(opts.Location.ID) + reqBody.Location = strconv.FormatInt(opts.Location.ID, 10) } else { reqBody.Location = opts.Location.Name } } if opts.Datacenter != nil { if opts.Datacenter.ID != 0 { - reqBody.Datacenter = strconv.Itoa(opts.Datacenter.ID) + reqBody.Datacenter = strconv.FormatInt(opts.Datacenter.ID, 10) } else { reqBody.Datacenter = opts.Datacenter.Name } diff --git a/hcloud/server_test.go b/hcloud/server_test.go index 0207a558f..3551732b1 100644 --- a/hcloud/server_test.go +++ b/hcloud/server_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestServerClientGetByID(t *testing.T) { diff --git a/hcloud/server_type.go b/hcloud/server_type.go index c5e03253c..f3aa2881c 100644 --- a/hcloud/server_type.go +++ b/hcloud/server_type.go @@ -6,12 +6,12 @@ import ( "net/url" "strconv" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // ServerType represents a server type in the Hetzner Cloud. type ServerType struct { - ID int + ID int64 Name string Description string Cores int @@ -54,7 +54,7 @@ type ServerTypeClient struct { } // GetByID retrieves a server type by its ID. If the server type does not exist, nil is returned. -func (c *ServerTypeClient) GetByID(ctx context.Context, id int) (*ServerType, *Response, error) { +func (c *ServerTypeClient) GetByID(ctx context.Context, id int64) (*ServerType, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/server_types/%d", id), nil) if err != nil { return nil, nil, err @@ -86,8 +86,8 @@ func (c *ServerTypeClient) GetByName(ctx context.Context, name string) (*ServerT // Get retrieves a server type by its ID if the input can be parsed as an integer, otherwise it // retrieves a server type by its name. If the server type does not exist, nil is returned. func (c *ServerTypeClient) Get(ctx context.Context, idOrName string) (*ServerType, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/server_type_test.go b/hcloud/server_type_test.go index acb40ac29..af60a0f96 100644 --- a/hcloud/server_type_test.go +++ b/hcloud/server_type_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestServerTypeClient(t *testing.T) { diff --git a/hcloud/ssh_key.go b/hcloud/ssh_key.go index f450c8b92..03bb0c5db 100644 --- a/hcloud/ssh_key.go +++ b/hcloud/ssh_key.go @@ -10,12 +10,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // SSHKey represents a SSH key in the Hetzner Cloud. type SSHKey struct { - ID int + ID int64 Name string Fingerprint string PublicKey string @@ -29,7 +29,7 @@ type SSHKeyClient struct { } // GetByID retrieves a SSH key by its ID. If the SSH key does not exist, nil is returned. -func (c *SSHKeyClient) GetByID(ctx context.Context, id int) (*SSHKey, *Response, error) { +func (c *SSHKeyClient) GetByID(ctx context.Context, id int64) (*SSHKey, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/ssh_keys/%d", id), nil) if err != nil { return nil, nil, err @@ -70,8 +70,8 @@ func (c *SSHKeyClient) GetByFingerprint(ctx context.Context, fingerprint string) // Get retrieves a SSH key by its ID if the input can be parsed as an integer, otherwise it // retrieves a SSH key by its name. If the SSH key does not exist, nil is returned. func (c *SSHKeyClient) Get(ctx context.Context, idOrName string) (*SSHKey, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/ssh_key_test.go b/hcloud/ssh_key_test.go index d69940877..abc0d1f56 100644 --- a/hcloud/ssh_key_test.go +++ b/hcloud/ssh_key_test.go @@ -7,7 +7,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestSSHKeyClientGetByID(t *testing.T) { diff --git a/hcloud/volume.go b/hcloud/volume.go index f939d89bb..b296e729e 100644 --- a/hcloud/volume.go +++ b/hcloud/volume.go @@ -10,12 +10,12 @@ import ( "strconv" "time" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) // Volume represents a volume in the Hetzner Cloud. type Volume struct { - ID int + ID int64 Name string Status VolumeStatus Server *Server @@ -49,7 +49,7 @@ const ( ) // GetByID retrieves a volume by its ID. If the volume does not exist, nil is returned. -func (c *VolumeClient) GetByID(ctx context.Context, id int) (*Volume, *Response, error) { +func (c *VolumeClient) GetByID(ctx context.Context, id int64) (*Volume, *Response, error) { req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/volumes/%d", id), nil) if err != nil { return nil, nil, err @@ -81,8 +81,8 @@ func (c *VolumeClient) GetByName(ctx context.Context, name string) (*Volume, *Re // Get retrieves a volume by its ID if the input can be parsed as an integer, otherwise it // retrieves a volume by its name. If the volume does not exist, nil is returned. func (c *VolumeClient) Get(ctx context.Context, idOrName string) (*Volume, *Response, error) { - if id, err := strconv.Atoi(idOrName); err == nil { - return c.GetByID(ctx, int(id)) + if id, err := strconv.ParseInt(idOrName, 10, 64); err == nil { + return c.GetByID(ctx, id) } return c.GetByName(ctx, idOrName) } diff --git a/hcloud/volume_test.go b/hcloud/volume_test.go index 025ee174e..8e2255a31 100644 --- a/hcloud/volume_test.go +++ b/hcloud/volume_test.go @@ -7,7 +7,7 @@ import ( "net/http" "testing" - "github.com/hetznercloud/hcloud-go/hcloud/schema" + "github.com/hetznercloud/hcloud-go/v2/hcloud/schema" ) func TestVolumeClientGet(t *testing.T) {