package factory import ( "fmt" "os" "github.com/rs/zerolog" "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 config *config.MainConfig logger zerolog.Logger } func New(logger zerolog.Logger, config *config.MainConfig) Factory { return Factory{ config: config, logger: logger, } } func NewFromConfig() Factory { config, err := config.GetMainConfig() if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) os.Exit(1) } log := logging.Logger(config.Logger) log.Info().Object("config", &config).Msg("configuration") return New(log, &config) } func (f *Factory) Logger() zerolog.Logger { return f.logger } func (f *Factory) Something() *something.Something { if f.something == nil { something := something.New( &f.config.Something, ) f.something = &something } return f.something }