From c2d6c4f003833712ce7d50a8b79370b0785c9f19 Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Thu, 15 Aug 2024 12:02:34 +0100 Subject: [PATCH 1/2] add object.DefinitionHolder to the connector struct --- v1/connector/connector.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/v1/connector/connector.go b/v1/connector/connector.go index 7ac958c..bb3ce88 100644 --- a/v1/connector/connector.go +++ b/v1/connector/connector.go @@ -48,7 +48,10 @@ func NewDefinition(d *object.Definition) (*Definition, error) { } // Definition is the connector definition structure -type Definition struct{ def *object.Definition } +type Definition struct { + object.DefinitionHolder + def *object.Definition +} // Definition returns the Definition for a connector func (d *Definition) Definition() *object.Definition { return d.def } From f19e53749bbb62278cfacb87766cb745143cae1c Mon Sep 17 00:00:00 2001 From: Tom Kay Date: Thu, 15 Aug 2024 12:16:48 +0100 Subject: [PATCH 2/2] create Definitions type --- object/object.go | 10 ++++++++++ v1/connector/connector.go | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/object/object.go b/object/object.go index 640c9a9..42ffe28 100644 --- a/object/object.go +++ b/object/object.go @@ -86,3 +86,13 @@ func DefinitionFromSpec(specification Specification) *Definition { type DefinitionHolder interface { Definition() *Definition } + +type Definitions []DefinitionHolder + +func (c Definitions) Len() int { return len(c) } +func (c Definitions) Swap(i, j int) { c[i], c[j] = c[j], c[i] } +func (c Definitions) Less(i, j int) bool { + return c[i].Definition().Selector.Priority > c[j].Definition().Selector.Priority || + (c[i].Definition().Selector.Priority == c[j].Definition().Selector.Priority && + c[i].Definition().MetaData.Name > c[j].Definition().MetaData.Name) +} diff --git a/v1/connector/connector.go b/v1/connector/connector.go index bb3ce88..7ac958c 100644 --- a/v1/connector/connector.go +++ b/v1/connector/connector.go @@ -48,10 +48,7 @@ func NewDefinition(d *object.Definition) (*Definition, error) { } // Definition is the connector definition structure -type Definition struct { - object.DefinitionHolder - def *object.Definition -} +type Definition struct{ def *object.Definition } // Definition returns the Definition for a connector func (d *Definition) Definition() *object.Definition { return d.def }