Skip to content

Commit

Permalink
Replace string interpolation with struct
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Sep 14, 2023
1 parent 25fd000 commit eb2bd3e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/xray/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit eb2bd3e

Please sign in to comment.