44 "fmt"
55 "reflect"
66
7- "github.com/spiral/endure/structures"
87 "github.com/spiral/errors"
98 "go.uber.org/zap"
109)
@@ -32,17 +31,17 @@ func (e *Endure) addProviders(vertexID string, vertex interface{}) error {
3231 // get the Vertex from the graph (gVertex)
3332 gVertex := e .graph .GetVertex (vertexID )
3433 if gVertex .Provides == nil {
35- gVertex .Provides = make (map [string ]structures. ProvidedEntry )
34+ gVertex .Provides = make (map [string ]ProvidedEntry )
3635 }
3736
3837 // Make a slice
3938 if gVertex .Meta .FnsProviderToInvoke == nil {
40- gVertex .Meta .FnsProviderToInvoke = make ([]structures. ProviderEntry , 0 , 1 )
39+ gVertex .Meta .FnsProviderToInvoke = make ([]ProviderEntry , 0 , 1 )
4140 }
4241
4342 // TODO merge function calls into one. Plugin1 -> fn's to invoke ProvideDB, ProvideDB2
4443 // Append functions which we will invoke when we start calling the structure functions after Init stage
45- gVertex .Meta .FnsProviderToInvoke = append (gVertex .Meta .FnsProviderToInvoke , structures. ProviderEntry {
44+ gVertex .Meta .FnsProviderToInvoke = append (gVertex .Meta .FnsProviderToInvoke , ProviderEntry {
4645 /*
4746 For example:
4847 we need to invoke function ProvideDB - that will be FunctionName
@@ -64,13 +63,13 @@ func (e *Endure) addProviders(vertexID string, vertex interface{}) error {
6463 if reflect .TypeOf (vertex ).Implements (ret ) {
6564 tmpValue := reflect .ValueOf (vertex )
6665 tmpIsRef := isReference (ret )
67- gVertex .Provides [typeStr ] = structures. ProvidedEntry {
66+ gVertex .Provides [typeStr ] = ProvidedEntry {
6867 IsReference : & tmpIsRef ,
6968 Value : & tmpValue ,
7069 }
7170 }
7271 } else {
73- gVertex .Provides [typeStr ] = structures. ProvidedEntry {
72+ gVertex .Provides [typeStr ] = ProvidedEntry {
7473 IsReference : nil ,
7574 Value : nil ,
7675 }
@@ -82,19 +81,19 @@ func (e *Endure) addProviders(vertexID string, vertex interface{}) error {
8281
8382// addEdges calculates simple graph for the dependencies
8483func (e * Endure ) addEdges () error {
85- const Op = "add_edges"
84+ const Op = errors . Op ( "add_edges" )
8685 // vertexID for example S2
8786 for vertexID , vrtx := range e .graph .VerticesMap {
8887 // we already checked the interface satisfaction
8988 // and we can safely skip the OK parameter here
9089 init , _ := reflect .TypeOf (vrtx .Iface ).MethodByName (InitMethodName )
9190
9291 if init .Type == nil {
93- e .logger .Fatal ("init method is absent in struct" , zap .String ("vertex id" , vertexID ))
94- return errors .E (Op , fmt .Errorf ("init method is absent in struct" ))
92+ e .logger .Fatal ("internal_init method is absent in struct" , zap .String ("vertex id" , vertexID ))
93+ return errors .E (Op , fmt .Errorf ("internal_init method is absent in struct" ))
9594 }
9695
97- /* Add the dependencies (if) which this vertex needs to init
96+ /* Add the dependencies (if) which this vertex needs to internal_init
9897 Information we know at this step is:
9998 1. vertexID
10099 2. Vertex structure value (interface)
@@ -124,7 +123,7 @@ func (e *Endure) addEdges() error {
124123}
125124
126125func (e * Endure ) addCollectorsDeps (vertexID string , vertex interface {}) error {
127- const Op = "add_collectors_deps"
126+ const Op = errors . Op ( "add_collectors_deps" )
128127 if register , ok := vertex .(Collector ); ok {
129128 for _ , fn := range register .Collects () {
130129 // what type it might depend on?
@@ -167,7 +166,7 @@ func (e *Endure) addCollectorsDeps(vertexID string, vertex interface{}) error {
167166 // vertex - S4 func
168167
169168 // we store pointer in the Deps structure in the isRef field
170- err = e .graph .AddDep (vertexID , removePointerAsterisk (atStr ), structures . Collects , isReference (at ), at .Kind ())
169+ err = e .graph .AddDep (vertexID , removePointerAsterisk (atStr ), Collects , isReference (at ), at .Kind ())
171170 if err != nil {
172171 return errors .E (Op , err )
173172 }
@@ -177,7 +176,7 @@ func (e *Endure) addCollectorsDeps(vertexID string, vertex interface{}) error {
177176 // get the Vertex from the graph (gVertex)
178177 gVertex := e .graph .GetVertex (vertexID )
179178 if gVertex .Provides == nil {
180- gVertex .Provides = make (map [string ]structures. ProvidedEntry )
179+ gVertex .Provides = make (map [string ]ProvidedEntry )
181180 }
182181
183182 if gVertex .Meta .FnsCollectorToInvoke == nil {
@@ -194,7 +193,7 @@ func (e *Endure) addCollectorsDeps(vertexID string, vertex interface{}) error {
194193}
195194
196195func (e * Endure ) addInitDeps (vertexID string , initMethod reflect.Method ) error {
197- const Op = "add_init_deps"
196+ const Op = errors . Op ( "add_init_deps" )
198197 // Init function in arguments
199198 initArgs := functionParameters (initMethod )
200199
@@ -223,11 +222,11 @@ func (e *Endure) addInitDeps(vertexID string, initMethod reflect.Method) error {
223222 }
224223 }
225224
226- err := e .graph .AddDep (vertexID , removePointerAsterisk (initArg .String ()), structures . Init , isReference (initArg ), initArg .Kind ())
225+ err := e .graph .AddDep (vertexID , removePointerAsterisk (initArg .String ()), Init , isReference (initArg ), initArg .Kind ())
227226 if err != nil {
228227 return errors .E (Op , err )
229228 }
230- e .logger .Debug ("adding dependency via Init()" , zap .String ("vertex id" , vertexID ), zap .String ("depends" , initArg .String ()))
229+ e .logger .Debug ("adding dependency via Init()" , zap .String ("vertex id" , vertexID ), zap .String ("depends on " , initArg .String ()))
231230 }
232231 return nil
233232}
0 commit comments