mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 02:48:21 +00:00
Fix Address Type
This commit is contained in:
parent
2c1df2a4ad
commit
d9ecfae454
2 changed files with 33 additions and 1 deletions
|
@ -8,7 +8,7 @@ type Interface struct {
|
||||||
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
|
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
|
||||||
Type InterfaceType `json:"type" validate:"min=0,max=3"`
|
Type InterfaceType `json:"type" validate:"min=0,max=3"`
|
||||||
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
|
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
|
||||||
Address *IPNet `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
|
Address *IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
|
||||||
HardwareInterface *string `json:"hardware_interface,omitempty"`
|
HardwareInterface *string `json:"hardware_interface,omitempty"`
|
||||||
// TODO fix Validator for int pointers with min=0,max=4094
|
// TODO fix Validator for int pointers with min=0,max=4094
|
||||||
VlanID *uint `json:"vlan_id,omitempty"`
|
VlanID *uint `json:"vlan_id,omitempty"`
|
||||||
|
|
32
internal/definitions/ipcidr.go
Normal file
32
internal/definitions/ipcidr.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package definitions
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IPCIDR is IP Address with the mask in CIDR format
|
||||||
|
type IPCIDR struct {
|
||||||
|
net.IPNet
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON for IPCIDR
|
||||||
|
func (i IPCIDR) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(i.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON for IPCIDR
|
||||||
|
func (i *IPCIDR) UnmarshalJSON(b []byte) error {
|
||||||
|
var s string
|
||||||
|
if err := json.Unmarshal(b, &s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ip, ipnet, err := net.ParseCIDR(s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
i.IPNet = *ipnet
|
||||||
|
i.IPNet.IP = ip
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue