From c5ff8c85939acb7c858aafb65ee48e30fd85a924 Mon Sep 17 00:00:00 2001 From: Paul Tyng Date: Tue, 1 Dec 2020 12:31:29 -0500 Subject: [PATCH] Allow unmarshalling of string for rule index --- unifi/firewall_rule.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/unifi/firewall_rule.go b/unifi/firewall_rule.go index fc6e3cc..6855a5b 100644 --- a/unifi/firewall_rule.go +++ b/unifi/firewall_rule.go @@ -1,6 +1,30 @@ package unifi -import "context" +import ( + "context" + "encoding/json" + "fmt" +) + +func (dst *FirewallRule) UnmarshalJSON(b []byte) error { + type Alias FirewallRule + aux := &struct { + RuleIndex emptyStringInt `json:"rule_index"` + + *Alias + }{ + Alias: (*Alias)(dst), + } + + err := json.Unmarshal(b, &aux) + if err != nil { + return fmt.Errorf("unable to unmarshal alias: %w", err) + } + + dst.RuleIndex = int(aux.RuleIndex) + + return nil +} func (c *Client) ListFirewallRule(ctx context.Context, site string) ([]FirewallRule, error) { return c.listFirewallRule(ctx, site)