github.com/alkemics/goflow@v0.2.1/wrappers/ctx/injector.go (about) 1 package ctx 2 3 import "github.com/alkemics/goflow" 4 5 type Injector struct { 6 goflow.NodeRenderer 7 } 8 9 func (n Injector) Inputs() []goflow.Field { 10 inputs := n.NodeRenderer.Inputs() 11 12 // Add context as first input if not present yet 13 if len(inputs) > 0 && inputs[0].Type != "context.Context" { 14 inputs = append( 15 []goflow.Field{{ 16 Name: "ctx", 17 Type: "context.Context", 18 }}, 19 inputs..., 20 ) 21 } 22 23 return inputs 24 } 25 26 func (n Injector) Run(inputs, outputs []goflow.Field) (string, error) { 27 originalInputs := n.NodeRenderer.Inputs() 28 29 if len(originalInputs) > 0 && originalInputs[0].Type != "context.Context" { 30 inputs = inputs[1:] 31 } 32 33 return n.NodeRenderer.Run(inputs, outputs) 34 }