Refactor Route IDs (#1891)

This commit is contained in:
Viktor Liu
2024-05-06 14:47:49 +02:00
committed by GitHub
parent 6a4935139d
commit 4e7c17756c
25 changed files with 320 additions and 292 deletions

View File

@ -36,6 +36,12 @@ const (
IPv6Network
)
type ID string
type NetID string
type HAMap map[HAUniqueID][]*Route
// NetworkType route network type
type NetworkType int
@ -65,11 +71,11 @@ func ToPrefixType(prefix string) NetworkType {
// Route represents a route
type Route struct {
ID string `gorm:"primaryKey"`
ID ID `gorm:"primaryKey"`
// AccountID is a reference to Account that this object belongs
AccountID string `gorm:"index"`
Network netip.Prefix `gorm:"serializer:json"`
NetID string
NetID NetID
Description string
Peer string
PeerGroups []string `gorm:"serializer:json"`
@ -165,8 +171,3 @@ func compareList(list, other []string) bool {
return true
}
// GetHAUniqueID returns a highly available route ID by combining Network ID and Network range address
func GetHAUniqueID(input *Route) string {
return input.NetID + "-" + input.Network.String()
}