Fix type of lte_ext_ant/lte_poe fields (#89)

This commit is contained in:
jeanluc
2022-08-10 01:34:05 +00:00
committed by GitHub
parent dd7be9a4f1
commit 1ac863de1f
3 changed files with 35 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
package unifi
import (
"errors"
"strconv"
"strings"
)
@@ -66,3 +67,24 @@ func (e *emptyStringInt) MarshalJSON() ([]byte, error) {
return []byte(strconv.Itoa(int(*e))), nil
}
type booleanishString bool
func (e *booleanishString) UnmarshalJSON(b []byte) error {
s := string(b)
if s == `"enabled"` {
*e = booleanishString(true)
return nil
} else if s == `"disabled"` {
*e = booleanishString(false)
return nil
}
return errors.New("Could not unmarshal JSON value.")
}
func (e *booleanishString) MarshalJSON(b []byte) ([]byte, error) {
if *e == true {
return []byte(`"enabled"`), nil
}
return []byte(`"disabled"`), nil
}