From 9cef8ed8822297eaa99e83f0310e16ca5c1e1f15 Mon Sep 17 00:00:00 2001 From: Adnan Hajdarevic Date: Sat, 21 Nov 2015 17:06:02 +0100 Subject: [PATCH 1/2] add omitempty to json fields --- hook/hook.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/hook/hook.go b/hook/hook.go index e01d078d..7bff5d85 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -195,8 +195,8 @@ func ExtractParameterAsString(s string, params interface{}) (string, bool) { // Argument type specifies the parameter key name and the source it should // be extracted from type Argument struct { - Source string `json:"source"` - Name string `json:"name"` + Source string `json:"source,omitempty"` + Name string `json:"name,omitempty"` } // Get Argument method returns the value for the Argument's key name @@ -248,15 +248,15 @@ func (ha *Argument) Get(headers, query, payload *map[string]interface{}) (string // Hook type is a structure containing details for a single hook type Hook struct { - ID string `json:"id"` - ExecuteCommand string `json:"execute-command"` - CommandWorkingDirectory string `json:"command-working-directory"` - ResponseMessage string `json:"response-message"` - CaptureCommandOutput bool `json:"include-command-output-in-response"` - PassEnvironmentToCommand []Argument `json:"pass-environment-to-command"` - PassArgumentsToCommand []Argument `json:"pass-arguments-to-command"` - JSONStringParameters []Argument `json:"parse-parameters-as-json"` - TriggerRule *Rules `json:"trigger-rule"` + ID string `json:"id,omitempty"` + ExecuteCommand string `json:"execute-command,omitempty"` + CommandWorkingDirectory string `json:"command-working-directory,omitempty"` + ResponseMessage string `json:"response-message,omitempty"` + CaptureCommandOutput bool `json:"include-command-output-in-response,omitempty"` + PassEnvironmentToCommand []Argument `json:"pass-environment-to-command,omitempty"` + PassArgumentsToCommand []Argument `json:"pass-arguments-to-command,omitempty"` + JSONStringParameters []Argument `json:"parse-parameters-as-json,omitempty"` + TriggerRule *Rules `json:"trigger-rule,omitempty"` } // ParseJSONParameters decodes specified arguments to JSON objects and replaces the @@ -386,10 +386,10 @@ func (h *Hooks) MatchAll(id string) []*Hook { // Rules is a structure that contains one of the valid rule types type Rules struct { - And *AndRule `json:"and"` - Or *OrRule `json:"or"` - Not *NotRule `json:"not"` - Match *MatchRule `json:"match"` + And *AndRule `json:"and,omitempty"` + Or *OrRule `json:"or,omitempty"` + Not *NotRule `json:"not,omitempty"` + Match *MatchRule `json:"match,omitempty"` } // Evaluate finds the first rule property that is not nil and returns the value @@ -464,11 +464,11 @@ func (r NotRule) Evaluate(headers, query, payload *map[string]interface{}, body // MatchRule will evaluate to true based on the type type MatchRule struct { - Type string `json:"type"` - Regex string `json:"regex"` - Secret string `json:"secret"` - Value string `json:"value"` - Parameter Argument `json:"parameter"` + Type string `json:"type,omitempty"` + Regex string `json:"regex,omitempty"` + Secret string `json:"secret,omitempty"` + Value string `json:"value,omitempty"` + Parameter Argument `json:"parameter,omitempty"` } // Constants for the MatchRule type From f59f0a5c84c40b6c659753137c66351f8413cd9a Mon Sep 17 00:00:00 2001 From: Adnan Hajdarevic Date: Sun, 27 Dec 2015 20:05:52 +0100 Subject: [PATCH 2/2] - added omitempty to json fields --- webhook.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webhook.go b/webhook.go index a116c909..94db972a 100644 --- a/webhook.go +++ b/webhook.go @@ -21,7 +21,7 @@ import ( ) const ( - version = "2.3.6" + version = "2.3.7" ) var (