From cdea74c0a284e178e2f3a2987ecedaf17a340012 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Fri, 7 May 2021 12:29:53 -0400 Subject: [PATCH 1/2] make backup schedule pointers to allow 0 --- govultr.go | 8 ++++++-- instance.go | 6 +++--- instance_test.go | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/govultr.go b/govultr.go index daa1e34..41c1969 100644 --- a/govultr.go +++ b/govultr.go @@ -235,11 +235,15 @@ func (c *Client) vultrErrorHandler(resp *http.Response, err error, numTries int) // BoolToBoolPtr helper function that returns a pointer from your bool value func BoolToBoolPtr(value bool) *bool { - b := value - return &b + return &value } // StringToStringPtr helper function that returns a pointer from your string value func StringToStringPtr(value string) *string { return &value } + +// IntToIntPtr helper function that returns a pointer from your string value +func IntToIntPtr(value int) *int { + return &value +} diff --git a/instance.go b/instance.go index 519b662..35eca9f 100644 --- a/instance.go +++ b/instance.go @@ -162,9 +162,9 @@ type BackupSchedule struct { // BackupScheduleReq struct used to create a backup schedule for an instance. type BackupScheduleReq struct { Type string `json:"type"` - Hour int `json:"hour,omitempty"` - Dow int `json:"dow,omitempty"` - Dom int `json:"dom,omitempty"` + Hour *int `json:"hour,omitempty"` + Dow *int `json:"dow,omitempty"` + Dom *int `json:"dom,omitempty"` } // RestoreReq struct used to supply whether a restore should be from a backup or snapshot. diff --git a/instance_test.go b/instance_test.go index 14c823c..0fb17e3 100644 --- a/instance_test.go +++ b/instance_test.go @@ -46,9 +46,9 @@ func TestServerServiceHandler_SetBackupSchedule(t *testing.T) { bs := &BackupScheduleReq{ Type: "weekly", - Hour: 22, - Dow: 2, - Dom: 3, + Hour: IntToIntPtr(22), + Dow: IntToIntPtr(2), + Dom: IntToIntPtr(3), } if err := client.Instance.SetBackupSchedule(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", bs); err != nil { From 3f14abf6f45b091f0ce7ef027325780654617791 Mon Sep 17 00:00:00 2001 From: David Dymko Date: Mon, 10 May 2021 08:18:37 -0400 Subject: [PATCH 2/2] backup schedule : dom removing pointer --- instance.go | 2 +- instance_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instance.go b/instance.go index 35eca9f..104f9c4 100644 --- a/instance.go +++ b/instance.go @@ -164,7 +164,7 @@ type BackupScheduleReq struct { Type string `json:"type"` Hour *int `json:"hour,omitempty"` Dow *int `json:"dow,omitempty"` - Dom *int `json:"dom,omitempty"` + Dom int `json:"dom,omitempty"` } // RestoreReq struct used to supply whether a restore should be from a backup or snapshot. diff --git a/instance_test.go b/instance_test.go index 0fb17e3..51c3c81 100644 --- a/instance_test.go +++ b/instance_test.go @@ -48,7 +48,7 @@ func TestServerServiceHandler_SetBackupSchedule(t *testing.T) { Type: "weekly", Hour: IntToIntPtr(22), Dow: IntToIntPtr(2), - Dom: IntToIntPtr(3), + Dom: 3, } if err := client.Instance.SetBackupSchedule(ctx, "14b3e7d6-ffb5-4994-8502-57fcd9db3b33", bs); err != nil {