mirror of
https://github.com/speatzle/nfsense.git
synced 2025-09-13 15:19:08 +00:00
Seperate Definitions by Sub System
This commit is contained in:
parent
14c8da64cc
commit
72bf96295d
31 changed files with 120 additions and 108 deletions
91
internal/definitions/network/interface.go
Normal file
91
internal/definitions/network/interface.go
Normal file
|
@ -0,0 +1,91 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"nfsense.net/nfsense/internal/definitions/common"
|
||||
)
|
||||
|
||||
type Interface struct {
|
||||
Alias string `json:"alias,omitempty" validate:"min=0,max=3"`
|
||||
Type InterfaceType `json:"type" validate:"min=0,max=3"`
|
||||
AddressingMode InterfaceAddressingMode `json:"addressing_mode" validate:"min=0,max=2"`
|
||||
Address *common.IPCIDR `json:"address,omitempty" validate:"excluded_unless=AddressingMode 1"`
|
||||
HardwareDevice *string `json:"hardware_device,omitempty"`
|
||||
// TODO fix Validator for int pointers with min=0,max=4094
|
||||
VlanID *uint `json:"vlan_id,omitempty"`
|
||||
VlanParent *string `json:"vlan_parent,omitempty"`
|
||||
BondMembers *[]string `json:"bond_members,omitempty"`
|
||||
BridgeMembers *[]string `json:"bridge_members,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
}
|
||||
|
||||
type InterfaceType int
|
||||
|
||||
const (
|
||||
Hardware InterfaceType = iota
|
||||
Vlan
|
||||
Bond
|
||||
Bridge
|
||||
)
|
||||
|
||||
func (t InterfaceType) String() string {
|
||||
return [...]string{"hardware", "vlan", "bond", "bridge"}[t]
|
||||
}
|
||||
|
||||
func (t *InterfaceType) FromString(input string) InterfaceType {
|
||||
return map[string]InterfaceType{
|
||||
"hardware": Hardware,
|
||||
"vlan": Vlan,
|
||||
"bond": Bond,
|
||||
"bridge": Bridge,
|
||||
}[input]
|
||||
}
|
||||
|
||||
func (t InterfaceType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *InterfaceType) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = t.FromString(s)
|
||||
return nil
|
||||
}
|
||||
|
||||
type InterfaceAddressingMode int
|
||||
|
||||
const (
|
||||
None InterfaceAddressingMode = iota
|
||||
Static
|
||||
Dhcp
|
||||
)
|
||||
|
||||
func (t InterfaceAddressingMode) String() string {
|
||||
return [...]string{"none", "static", "dhcp"}[t]
|
||||
}
|
||||
|
||||
func (t *InterfaceAddressingMode) FromString(input string) InterfaceAddressingMode {
|
||||
return map[string]InterfaceAddressingMode{
|
||||
"none": None,
|
||||
"static": Static,
|
||||
"dhcp": Dhcp,
|
||||
}[input]
|
||||
}
|
||||
|
||||
func (t InterfaceAddressingMode) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(t.String())
|
||||
}
|
||||
|
||||
func (t *InterfaceAddressingMode) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = t.FromString(s)
|
||||
return nil
|
||||
}
|
6
internal/definitions/network/network.go
Normal file
6
internal/definitions/network/network.go
Normal file
|
@ -0,0 +1,6 @@
|
|||
package network
|
||||
|
||||
type Network struct {
|
||||
Interfaces map[string]Interface `json:"interfaces" validate:"required,dive"`
|
||||
StaticRoutes []StaticRoute `json:"static_routes" validate:"required,dive"`
|
||||
}
|
15
internal/definitions/network/static_route.go
Normal file
15
internal/definitions/network/static_route.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"nfsense.net/nfsense/internal/definitions/common"
|
||||
)
|
||||
|
||||
type StaticRoute struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Interface string `json:"interface,omitempty"`
|
||||
Gateway netip.Addr `json:"gateway,omitempty"`
|
||||
Destination common.IPNet `json:"destination,omitempty"`
|
||||
Metric uint `json:"metric,omitempty"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue