func init() {
	registerCompleteModule(&CompleteModule{
		base_modules.NewGenericModule("Complete Module", "1.0.0",
			"complete-module", "", "sample-module"),
		"",
		"",
	})
}
Exemple #2
0
func main() {
	fmt.Println("Number of sample modules :",
		base_modules.GetModuleCountByType("sample-module"))
	fmt.Println("Total number of modules  :",
		base_modules.GetAllModulesCount())

	simpleModule := base_modules.GetModuleById("simple-module", "").(*example_modules.SimpleModule)
	if simpleModule != nil {
		fmt.Println(simpleModule.GenericId(), simpleModule.Name(),
			simpleModule.Version())
	}

	completeModule := base_modules.GetModuleById("complete-module", "").(*example_modules.CompleteModule)
	if completeModule != nil {
		fmt.Println(completeModule.GenericId(), completeModule.Name(),
			completeModule.Version())
		// This will fail as module is not configured.
		err := completeModule.DoWork()
		if err != nil {
			fmt.Printf("error doing work : %v\n", err)
		}

		parameters := completeModule.Parameters()
		(*parameters)["text1"] = "This is text1"
		completeModule.Configure(parameters)

		// And now itwill work as expected.
		err = completeModule.DoWork()
		if err != nil {
			fmt.Printf("error doing work : %v\n", err)
		}
	}

	// Add a new complete module with a different specific id.
	base_modules.RegisterModule(base_modules.NewGenericModule(
		"Complete Module / Specific", "1.0.0",
		"complete-module", "specific", "sample-module"))

	fmt.Println("After adding new module.")
	fmt.Println("Number of sample modules :",
		base_modules.GetModuleCountByType("sample-module"))
	fmt.Println("Total number of modules  :",
		base_modules.GetAllModulesCount())

	completeModuleSpecific := base_modules.GetModuleById("complete-module", "specific")
	if completeModuleSpecific == nil {
		fmt.Println("Could not get reference to specific module.")
	}
	completeModuleDefault := base_modules.GetDefaultModuleByGenericId("complete-module")
	if completeModuleDefault == nil {
		fmt.Println("Could not get reference to default module.")
	}

	fmt.Println(completeModuleSpecific.Name())
	fmt.Println(completeModuleDefault.Name())
}
func init() {
	base_modules.RegisterModule(&SimpleModule2{
		base_modules.NewGenericModule("Simple Module 2", "1.0.0",
			"simple-module-2", "", "dummy-module"),
	})
}