// RegisterTypes registers all types that have been defined in the file "types.yml" // // DO NOT EDIT THIS FILE: it has been generated by goldigen v0.9.9. // It is however good practice to put this file under version control. // See https://github.com/fgrosse/goldi for what is going on here. func RegisterTypes(types goldi.TypeRegistry) { types.RegisterAll(map[string]goldi.TypeFactory{ "kernel.http_handler": goldi.NewAliasType("servo.routing.router::ServeHTTP"), "servo.routing.loader": goldi.NewStructType(new(Loader)), "servo.routing.router": goldi.NewType(NewRouter, "@servo.routing.loader", "@container"), }) }
// RegisterTypes registers all types that have been defined in the file "types.yml" // // DO NOT EDIT THIS FILE: it has been generated by goldigen v0.9.9. // It is however good practice to put this file under version control. // See https://github.com/fgrosse/goldi for what is going on here. func RegisterTypes(types goldi.TypeRegistry) { types.RegisterAll(map[string]goldi.TypeFactory{ "logger_provider": goldi.NewAliasType("logxi.logger_provider"), "logxi.configurator": goldi.NewType(NewLoggerConfigurator, "%logxi.level%"), "logxi.logger_provider": goldi.NewConfiguredType( goldi.NewStructType(new(LoggerProvider)), "logxi.configurator", "Configure", ), }) }
// RegisterTypes registers all types that have been defined in the file "config/types.yml" // // DO NOT EDIT THIS FILE: it has been generated by goldigen v0.9.9. // It is however good practice to put this file under version control. // See https://github.com/fgrosse/goldi for what is going on here. func RegisterTypes(types goldi.TypeRegistry) { types.RegisterAll(map[string]goldi.TypeFactory{ "composed_endpoint": goldi.NewType(handler.Composed, "@my_controller::OuterHandlerAction", "@my_controller::SecondHandlerAction", "@my_controller::FancyAction"), "container_aware_endpoint": goldi.NewFuncReferenceType("my_container_aware_controller", "SomeAction"), "controller_endpoint": goldi.NewFuncReferenceType("my_controller", "FancyAction"), "custom_error_handler": goldi.NewStructType(new(lib.MyErrorHandler)), "error_endpoint": goldi.NewFuncReferenceType("my_controller", "ErrorAction"), "greet_user_endpoint": goldi.NewFuncType(endpoints.GreetUserEndpoint), "homepage_endpoint": goldi.NewFuncType(endpoints.HomepageEndpoint), "kernel.http_handler": goldi.NewType(handler.MiddleWareAdapter, "@servo.routing.router", "@my_app.error_handler", "@my_app.logging_adapter"), "my_app.error_handler": goldi.NewType(middleware.ErrorHandlingAdapter, "@custom_error_handler::HandleEndpointError"), "my_app.logging_adapter": goldi.NewType(middleware.LoggingAdapter, "@my_logger"), "my_container_aware_controller": goldi.NewStructType(new(endpoints.ContainerAwareController), "@container"), "my_controller": goldi.NewStructType(new(endpoints.FancyController), "@my_service_client"), "my_logger": goldi.NewProxyType("logger_provider", "GetLogger", "my_app"), "my_service_client": goldi.NewType(lib.NewMockServiceClient, "%my_app.some_parameter%"), }) }
package validation_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/fgrosse/goldi" "github.com/fgrosse/goldi/validation" ) var _ = Describe("ContainerValidator", func() { var ( registry goldi.TypeRegistry config map[string]interface{} container *goldi.Container validator *validation.ContainerValidator ) BeforeEach(func() { registry = goldi.NewTypeRegistry() config = map[string]interface{}{} container = goldi.NewContainer(registry, config) validator = validation.NewContainerValidator() }) It("should return an error if an invalid type was registered", func() { registry.Register("main_type", goldi.NewFuncReferenceType("not_existent", "type")) Expect(validator.Validate(container)).NotTo(Succeed()) })
if err != nil { fmt.Println(err.Error()) return } // do stuff with the logger. usually you need a type assertion fmt.Printf("%T", l.(*NullLogger)) // Output: // *goldi_test.NullLogger } var _ = Describe("Container", func() { var ( registry goldi.TypeRegistry config map[string]interface{} container *goldi.Container ) BeforeEach(func() { registry = goldi.NewTypeRegistry() config = map[string]interface{}{} container = goldi.NewContainer(registry, config) }) It("should panic if a type can not be resolved", func() { Expect(func() { container.MustGet("foo.bar") }).To(Panic()) }) It("should return an error if there was an issue generating the type", func() { container.Register("foo", goldi.NewStructType(nil))
package goldi_test import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "fmt" "github.com/fgrosse/goldi" ) var _ = Describe("TypeRegistry", func() { var ( registry goldi.TypeRegistry resolver *goldi.ParameterResolver ) BeforeEach(func() { registry = goldi.NewTypeRegistry() container := goldi.NewContainer(registry, map[string]interface{}{}) resolver = goldi.NewParameterResolver(container) }) Describe("RegisterType", func() { Context("with factory function type", func() { It("should store the type", func() { typeID := "test_type" factory := &MockTypeFactory{} registry.RegisterType(typeID, factory.NewMockType) factoryWrapper, typeIsRegistered := registry[typeID] Expect(typeIsRegistered).To(BeTrue())