MCPcopy Index your code
hub / github.com/cortexproject/cortex / initModule

Method initModule

pkg/util/modules/modules.go:87–127  ·  view source on GitHub ↗
(name string, initMap map[string]bool, servicesMap map[string]services.Service)

Source from the content-addressed store, hash-verified

85}
86
87func (m *Manager) initModule(name string, initMap map[string]bool, servicesMap map[string]services.Service) error {
88 if _, ok := m.modules[name]; !ok {
89 return fmt.Errorf("unrecognised module name: %s", name)
90 }
91
92 // initialize all of our dependencies first
93 deps := m.orderedDeps(name)
94 deps = append(deps, name) // lastly, initialize the requested module
95
96 for ix, n := range deps {
97 // Skip already initialized modules
98 if initMap[n] {
99 continue
100 }
101
102 mod := m.modules[n]
103
104 var serv services.Service
105
106 if mod.initFn != nil {
107 s, err := mod.initFn()
108 if err != nil {
109 return errors.Wrap(err, fmt.Sprintf("error initialising module: %s", n))
110 }
111
112 if s != nil {
113 // We pass servicesMap, which isn't yet complete. By the time service starts,
114 // it will be fully built, so there is no need for extra synchronization.
115 serv = newModuleServiceWrapper(servicesMap, n, m.logger, s, m.DependenciesForModule(n), m.findInverseDependencies(n, deps[ix+1:]))
116 }
117 }
118
119 if serv != nil {
120 servicesMap[n] = serv
121 }
122
123 initMap[n] = true
124 }
125
126 return nil
127}
128
129// UserVisibleModuleNames gets list of module names that are
130// user visible. Returned list is sorted in increasing order.

Callers 1

InitModuleServicesMethod · 0.95

Calls 5

orderedDepsMethod · 0.95
DependenciesForModuleMethod · 0.95
newModuleServiceWrapperFunction · 0.85
WrapMethod · 0.65

Tested by

no test coverage detected