From eb2bd3ea30a4391e4d2931de91c06356608aaa38 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Thu, 14 Sep 2023 14:46:06 -0700 Subject: [PATCH] Replace string interpolation with struct --- pkg/xray/watches.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/xray/watches.go b/pkg/xray/watches.go index 5d888805..7323d94c 100644 --- a/pkg/xray/watches.go +++ b/pkg/xray/watches.go @@ -173,22 +173,26 @@ func unpackAntFilters(d *schema.Set, filterType string) []WatchFilter { var filters []WatchFilter + type antFilterValue struct { + ExcludePatterns []string `json:"ExcludePatterns"` + IncludePatterns []string `json:"IncludePatterns"` + } + for _, raw := range tfFilters { antValue := raw.(map[string]interface{}) // create JSON string from slice: // from []string{"a", "b"} to `["ExcludePatterns": ["a", "b"]]` - excludePatterns, _ := json.Marshal(sdk.CastToStringArr(antValue["exclude_patterns"].([]interface{}))) - includePatterns, _ := json.Marshal(sdk.CastToStringArr(antValue["include_patterns"].([]interface{}))) - filterJsonString := fmt.Sprintf( - `{"ExcludePatterns": %s, "IncludePatterns": %s}`, - excludePatterns, - includePatterns, + filterValue, _ := json.Marshal( + &antFilterValue{ + ExcludePatterns: sdk.CastToStringArr(antValue["exclude_patterns"].([]interface{})), + IncludePatterns: sdk.CastToStringArr(antValue["include_patterns"].([]interface{})), + }, ) filter := WatchFilter{ Type: filterType, - Value: json.RawMessage(filterJsonString), + Value: json.RawMessage(filterValue), } filters = append(filters, filter) }