Skip to content

Commit

Permalink
Allow unmarshalling of string for rule index
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Dec 1, 2020
1 parent 54b8578 commit c5ff8c8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion unifi/firewall_rule.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit c5ff8c8

Please sign in to comment.