From dda8c55193c68a341e25bc722bea6497d9a66a81 Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Thu, 19 Oct 2023 17:47:06 +0300 Subject: [PATCH] feat(models): add EvpnObject interface Signed-off-by: Boris Glimcher --- pkg/models/bridge.go | 3 +++ pkg/models/interface.go | 10 ++++++++++ pkg/models/port.go | 3 +++ pkg/models/svi.go | 3 +++ pkg/models/vrf.go | 3 +++ 5 files changed, 22 insertions(+) create mode 100644 pkg/models/interface.go diff --git a/pkg/models/bridge.go b/pkg/models/bridge.go index ff0d5113..0e4e8ba0 100644 --- a/pkg/models/bridge.go +++ b/pkg/models/bridge.go @@ -18,6 +18,9 @@ type Bridge struct { VtepIP net.IPNet } +// build time check that struct implements interface +var _ EvpnObject[*pb.LogicalBridge] = (*Bridge)(nil) + // NewBridge creates new SVI object from protobuf message func NewBridge(in *pb.LogicalBridge) *Bridge { // vtepip := make(net.IP, 4) diff --git a/pkg/models/interface.go b/pkg/models/interface.go new file mode 100644 index 00000000..a57daa1e --- /dev/null +++ b/pkg/models/interface.go @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (c) 2022-2023 Dell Inc, or its subsidiaries. + +// Package models translates frontend protobuf messages to backend messages +package models + +// EvpnObject is an interface for all domain objects in evpn-gw +type EvpnObject[T any] interface { + ToPb() (T, error) +} diff --git a/pkg/models/port.go b/pkg/models/port.go index 18769a38..03cc42e8 100644 --- a/pkg/models/port.go +++ b/pkg/models/port.go @@ -29,6 +29,9 @@ type Port struct { LogicalBridgeRefKeys []string } +// build time check that struct implements interface +var _ EvpnObject[*pb.BridgePort] = (*Port)(nil) + // NewPort creates new SVI object from protobuf message func NewPort(in *pb.BridgePort) *Port { mac := net.HardwareAddr(in.Spec.MacAddress) diff --git a/pkg/models/svi.go b/pkg/models/svi.go index 896756ca..9abbd5bd 100644 --- a/pkg/models/svi.go +++ b/pkg/models/svi.go @@ -21,6 +21,9 @@ type Svi struct { RemoteAs uint32 } +// build time check that struct implements interface +var _ EvpnObject[*pb.Svi] = (*Svi)(nil) + // NewSvi creates new SVI object from protobuf message func NewSvi(in *pb.Svi) *Svi { mac := net.HardwareAddr(in.Spec.MacAddress) diff --git a/pkg/models/vrf.go b/pkg/models/vrf.go index c49f8b08..72a797f2 100644 --- a/pkg/models/vrf.go +++ b/pkg/models/vrf.go @@ -21,6 +21,9 @@ type Vrf struct { MacAddress net.HardwareAddr } +// build time check that struct implements interface +var _ EvpnObject[*pb.Vrf] = (*Vrf)(nil) + // NewVrf creates new VRF object from protobuf message func NewVrf(in *pb.Vrf) *Vrf { mac := net.HardwareAddr(in.Status.Rmac)