createInlineModule is a helper function for config matchers that can create inline modules.
(c *container.C, preferredNamespace, modName string)
| 41 | |
| 42 | // createInlineModule is a helper function for config matchers that can create inline modules. |
| 43 | func createInlineModule(c *container.C, preferredNamespace, modName string) (module.Module, error) { |
| 44 | var newMod modules.FuncNewModule |
| 45 | originalModName := modName |
| 46 | |
| 47 | // First try to extend the name with preferred namespace unless the name |
| 48 | // already contains it. |
| 49 | if !strings.Contains(modName, ".") && preferredNamespace != "" { |
| 50 | modName = preferredNamespace + "." + modName |
| 51 | newMod = modules.Get(modName) |
| 52 | } |
| 53 | |
| 54 | // Then try global namespace for compatibility and complex modules. |
| 55 | if newMod == nil { |
| 56 | newMod = modules.Get(originalModName) |
| 57 | } |
| 58 | |
| 59 | // Bail if both failed. |
| 60 | if newMod == nil { |
| 61 | return nil, fmt.Errorf("unknown module: %s (namespace: %s)", originalModName, preferredNamespace) |
| 62 | } |
| 63 | |
| 64 | return newMod(c, modName, "") |
| 65 | } |
| 66 | |
| 67 | // configureInlineModule constructs "faked" config tree and passes it to module |
| 68 | // Init function to make it look like it is defined at top-level. |