mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-14 02:41:34 +01:00
21586acc16
Signed-off-by: bcmmbaga <bethuelmbaga12@gmail.com>
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
package networks
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/rs/xid"
|
|
)
|
|
|
|
type NetworkRouter struct {
|
|
ID string `gorm:"index"`
|
|
NetworkID string `gorm:"index"`
|
|
AccountID string `gorm:"index"`
|
|
Peer string
|
|
PeerGroups []string `gorm:"serializer:json"`
|
|
Masquerade bool
|
|
Metric int
|
|
}
|
|
|
|
func NewNetworkRouter(accountID string, networkID string, peer string, peerGroups []string, masquerade bool, metric int) (*NetworkRouter, error) {
|
|
if peer != "" && len(peerGroups) > 0 {
|
|
return nil, errors.New("peer and peerGroups cannot be set at the same time")
|
|
}
|
|
|
|
return &NetworkRouter{
|
|
ID: xid.New().String(),
|
|
AccountID: accountID,
|
|
NetworkID: networkID,
|
|
Peer: peer,
|
|
PeerGroups: peerGroups,
|
|
Masquerade: masquerade,
|
|
Metric: metric,
|
|
}, nil
|
|
}
|
|
|
|
func (n *NetworkRouter) Copy() *NetworkRouter {
|
|
return &NetworkRouter{
|
|
ID: n.ID,
|
|
NetworkID: n.NetworkID,
|
|
AccountID: n.AccountID,
|
|
Peer: n.Peer,
|
|
PeerGroups: n.PeerGroups,
|
|
Masquerade: n.Masquerade,
|
|
Metric: n.Metric,
|
|
}
|
|
}
|