From 1f2cb708c44233b1022a2c69b597a38fde1106ff Mon Sep 17 00:00:00 2001 From: De Ville Weppenaar Date: Thu, 26 Nov 2020 11:08:32 -0800 Subject: [PATCH 1/2] make AlertSettings pointer types; fixes #13 --- checkly_test.go | 18 +++++++++--------- types.go | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/checkly_test.go b/checkly_test.go index 1ee3b70..7236db8 100644 --- a/checkly_test.go +++ b/checkly_test.go @@ -71,18 +71,18 @@ var wantCheck = checkly.Check{ }, LocalSetupScript: "setitup", LocalTearDownScript: "tearitdown", - AlertSettings: checkly.AlertSettings{ + AlertSettings: &checkly.AlertSettings{ EscalationType: checkly.RunBased, - RunBasedEscalation: checkly.RunBasedEscalation{ + RunBasedEscalation: &checkly.RunBasedEscalation{ FailedRunThreshold: 1, }, - TimeBasedEscalation: checkly.TimeBasedEscalation{ + TimeBasedEscalation: &checkly.TimeBasedEscalation{ MinutesFailingThreshold: 5, }, - Reminders: checkly.Reminders{ + Reminders: &checkly.Reminders{ Interval: 5, }, - SSLCertificates: checkly.SSLCertificates{ + SSLCertificates: &checkly.SSLCertificates{ Enabled: false, AlertThreshold: 30, }, @@ -291,17 +291,17 @@ var wantGroup = checkly.Group{ UseGlobalAlertSettings: false, AlertSettings: checkly.AlertSettings{ EscalationType: checkly.RunBased, - RunBasedEscalation: checkly.RunBasedEscalation{ + RunBasedEscalation: &checkly.RunBasedEscalation{ FailedRunThreshold: 1, }, - TimeBasedEscalation: checkly.TimeBasedEscalation{ + TimeBasedEscalation: &checkly.TimeBasedEscalation{ MinutesFailingThreshold: 5, }, - Reminders: checkly.Reminders{ + Reminders: &checkly.Reminders{ Amount: 0, Interval: 5, }, - SSLCertificates: checkly.SSLCertificates{ + SSLCertificates: &checkly.SSLCertificates{ Enabled: true, AlertThreshold: 30, }, diff --git a/types.go b/types.go index 53b02be..19b8021 100644 --- a/types.go +++ b/types.go @@ -100,7 +100,7 @@ type Check struct { TearDownSnippetID int64 `json:"tearDownSnippetId,omitempty"` LocalSetupScript string `json:"localSetupScript,omitempty"` LocalTearDownScript string `json:"localTearDownScript,omitempty"` - AlertSettings AlertSettings `json:"alertSettings,omitempty"` + AlertSettings *AlertSettings `json:"alertSettings,omitempty"` UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"` Request Request `json:"request"` GroupID int64 `json:"groupId,omitempty"` @@ -157,11 +157,11 @@ type EnvironmentVariable struct { // AlertSettings represents an alert configuration. type AlertSettings struct { - EscalationType string `json:"escalationType,omitempty"` - RunBasedEscalation RunBasedEscalation `json:"runBasedEscalation,omitempty"` - TimeBasedEscalation TimeBasedEscalation `json:"timeBasedEscalation,omitempty"` - Reminders Reminders `json:"reminders,omitempty"` - SSLCertificates SSLCertificates `json:"sslCertificates,omitempty"` + EscalationType string `json:"escalationType,omitempty"` + RunBasedEscalation *RunBasedEscalation `json:"runBasedEscalation,omitempty"` + TimeBasedEscalation *TimeBasedEscalation `json:"timeBasedEscalation,omitempty"` + Reminders *Reminders `json:"reminders,omitempty"` + SSLCertificates *SSLCertificates `json:"sslCertificates,omitempty"` } // RunBasedEscalation represents an alert escalation based on a number of failed From d4f88d9e17ee935de2c30ba330695aa97df2dac7 Mon Sep 17 00:00:00 2001 From: De Ville Weppenaar Date: Thu, 26 Nov 2020 11:24:20 -0800 Subject: [PATCH 2/2] add omitempty to optional slices; fixes #14 --- types.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/types.go b/types.go index 19b8021..6b88177 100644 --- a/types.go +++ b/types.go @@ -88,13 +88,13 @@ type Check struct { Activated bool `json:"activated"` Muted bool `json:"muted"` ShouldFail bool `json:"shouldFail"` - Locations []string `json:"locations"` + Locations []string `json:"locations,omitempty"` DegradedResponseTime int `json:"degradedResponseTime"` MaxResponseTime int `json:"maxResponseTime"` Script string `json:"script,omitempty"` - EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"` + EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` DoubleCheck bool `json:"doubleCheck"` - Tags []string `json:"tags"` + Tags []string `json:"tags,omitempty"` SSLCheck bool `json:"sslCheck"` SetupSnippetID int64 `json:"setupSnippetId,omitempty"` TearDownSnippetID int64 `json:"tearDownSnippetId,omitempty"` @@ -114,9 +114,9 @@ type Request struct { FollowRedirects bool `json:"followRedirects"` Body string `json:"body"` BodyType string `json:"bodyType,omitempty"` - Headers []KeyValue `json:"headers"` - QueryParameters []KeyValue `json:"queryParameters"` - Assertions []Assertion `json:"assertions"` + Headers []KeyValue `json:"headers,omitempty"` + QueryParameters []KeyValue `json:"queryParameters,omitempty"` + Assertions []Assertion `json:"assertions,omitempty"` BasicAuth *BasicAuth `json:"basicAuth,omitempty"` } @@ -214,11 +214,11 @@ type Group struct { Name string `json:"name"` Activated bool `json:"activated"` Muted bool `json:"muted"` - Tags []string `json:"tags"` - Locations []string `json:"locations"` + Tags []string `json:"tags,omitempty"` + Locations []string `json:"locations,omitempty"` Concurrency int `json:"concurrency"` APICheckDefaults APICheckDefaults `json:"apiCheckDefaults"` - EnvironmentVariables []EnvironmentVariable `json:"environmentVariables"` + EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` DoubleCheck bool `json:"doubleCheck"` UseGlobalAlertSettings bool `json:"useGlobalAlertSettings"` AlertSettings AlertSettings `json:"alertSettings,omitempty"`