From b2dec1191a220ce47005d1a4ce3eda9443697987 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 17 Dec 2021 14:48:54 -0800 Subject: [PATCH] Remove interfaces and add extra info to instance --- internal/plugin/factory.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/plugin/factory.go b/internal/plugin/factory.go index a3c84a1ff..17faf81d3 100644 --- a/internal/plugin/factory.go +++ b/internal/plugin/factory.go @@ -152,6 +152,12 @@ func RubyFactory( // Instance is the result generated by the factory. This lets us pack // a bit more information into plugin-launched components. type Instance struct { + // Plugin name providing this component + Name string + + // Type of component provided in this instance + Type component.Type + // Component is the dispensed component Component interface{} @@ -161,15 +167,22 @@ type Instance struct { // The GRPCBroker attached to this plugin Broker *plugin.GRPCBroker + // Parent component + Parent *Instance + // Closer is a function that should be called to clean up resources // associated with this plugin. Close func() } -type PluginMetadata interface { - SetRequestMetadata(k, v string) +func (i *Instance) Parents() []string { + n := []string{} + for p := i; p != nil; p = p.Parent { + n = append(n, p.Name) + } + return n } -type hasGRPCBroker interface { - GRPCBroker() *plugin.GRPCBroker +func (i *Instance) ParentCount() int { + return len(i.Parents()) }