Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
haim-kermany committed Oct 6, 2024
1 parent ccae598 commit e98a4f8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/collector/data_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
firewallRuleJSONEntry = "firewall_rule"
segmentPortsJSONEntry = "segment_ports"
)

var nilWithType *struct{}

type Rule struct {
Expand All @@ -37,7 +38,9 @@ type Rule struct {

func (rule *Rule) UnmarshalJSON(b []byte) error {
rule.ServiceEntries = ServiceEntries{}
return UnmarshalBaseStructAndFields(b, &rule.Rule, serviceEntriesJSONEntry, &rule.ServiceEntries, firewallRuleJSONEntry, &rule.FirewallRule)
return UnmarshalBaseStructAndFields(b, &rule.Rule,
serviceEntriesJSONEntry, &rule.ServiceEntries,
firewallRuleJSONEntry, &rule.FirewallRule)
}

type FirewallRule struct {
Expand All @@ -51,7 +54,9 @@ type SecurityPolicy struct {
}

func (securityPolicy *SecurityPolicy) UnmarshalJSON(b []byte) error {
return UnmarshalBaseStructAndFields(b, &securityPolicy.SecurityPolicy, rulesJSONEntry, &securityPolicy.Rules, defaultRuleJSONEntry, &securityPolicy.DefaultRule)
return UnmarshalBaseStructAndFields(b, &securityPolicy.SecurityPolicy,
rulesJSONEntry, &securityPolicy.Rules,
defaultRuleJSONEntry, &securityPolicy.DefaultRule)
}

// /////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -333,7 +338,10 @@ func unmarshalFromRaw[t any](raw map[string]json.RawMessage, entry string, res *
return nil
}

func UnmarshalBaseStructAndFields[baseType any, fieldType1 any, fieldType2 any](b []byte, base *baseType, entry1 string, field1 *fieldType1, entry2 string, field2 *fieldType2) error {
func UnmarshalBaseStructAndFields[baseType any, fieldType1 any, fieldType2 any](
b []byte, base *baseType,
entry1 string, field1 *fieldType1,
entry2 string, field2 *fieldType2) error {
var raw map[string]json.RawMessage
if err := json.Unmarshal(b, &raw); err != nil {
return err
Expand Down

0 comments on commit e98a4f8

Please sign in to comment.