MCPcopy Index your code
hub / github.com/DoNewsCode/core / AddModuleFunc

Method AddModuleFunc

c.go:394–421  ·  view source on GitHub ↗

AddModuleFunc add the module after Invoking its constructor. Clean up functions and errors are handled automatically.

(constructor interface{})

Source from the content-addressed store, hash-verified

392// AddModuleFunc add the module after Invoking its constructor. Clean up
393// functions and errors are handled automatically.
394func (c *C) AddModuleFunc(constructor interface{}) {
395 c.provide(constructor)
396 ftype := reflect.TypeOf(constructor)
397 targetTypes := make([]reflect.Type, 0)
398 for i := 0; i < ftype.NumOut(); i++ {
399 if isErr(ftype.Out(i)) {
400 continue
401 }
402 if isCleanup(ftype.Out(i)) {
403 continue
404 }
405 outT := ftype.Out(i)
406 targetTypes = append(targetTypes, outT)
407 }
408
409 fnType := reflect.FuncOf(targetTypes, nil, false /* variadic */)
410 fn := reflect.MakeFunc(fnType, func(args []reflect.Value) []reflect.Value {
411 for _, arg := range args {
412 c.AddModule(arg.Interface())
413 }
414 return nil
415 })
416
417 err := c.di.Invoke(fn.Interface())
418 if err != nil {
419 panic(err)
420 }
421}
422
423// ApplyRootCommand iterates through every CommandProvider registered in the container,
424// and introduce the root *cobra.Command to everyone.

Callers 9

ExampleC_AddModuleFuncFunction · 0.80
TestC_DefaultFunction · 0.80
ExampleFunction · 0.80
TestModule_hotReloadFunction · 0.80
Test_integrationFunction · 0.80

Calls 5

provideMethod · 0.95
AddModuleMethod · 0.95
isErrFunction · 0.85
isCleanupFunction · 0.85
InvokeMethod · 0.80

Tested by 9

ExampleC_AddModuleFuncFunction · 0.64
TestC_DefaultFunction · 0.64
ExampleFunction · 0.64
TestModule_hotReloadFunction · 0.64
Test_integrationFunction · 0.64