From cafc27302d7fdf69934f3b5007ddf3f5e0fc1cd4 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 19 Dec 2024 15:16:56 +0000 Subject: add another package to better show the pattern --- factory/factory.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'factory/factory.go') diff --git a/factory/factory.go b/factory/factory.go index 2acac39..ad3262e 100644 --- a/factory/factory.go +++ b/factory/factory.go @@ -6,13 +6,15 @@ import ( "github.com/rs/zerolog" + "www.thenautilus.net/cgit/go-example/business" "www.thenautilus.net/cgit/go-example/config" "www.thenautilus.net/cgit/go-example/logging" "www.thenautilus.net/cgit/go-example/something" ) type Factory struct { - something *something.Something + somethingClient *something.Something + businessLogic *business.Logic config *config.MainConfig logger zerolog.Logger @@ -43,13 +45,25 @@ func (f *Factory) Logger() zerolog.Logger { return f.logger } -func (f *Factory) Something() *something.Something { - if f.something == nil { +func (f *Factory) SomethingClient() *something.Something { + if f.somethingClient == nil { something := something.New( &f.config.Something, ) - f.something = &something + f.somethingClient = &something } - return f.something + return f.somethingClient +} + +func (f *Factory) BusinessLogic() *business.Logic { + if f.businessLogic == nil { + logic := business.New( + &f.config.BusinessLogic, + f.SomethingClient(), + ) + f.businessLogic = &logic + } + + return f.businessLogic } -- cgit v1.2.3