Skip to content

Using this structure with MongoDB #69

Answered by stefanvanburen
A2-NieR asked this question in Q&A
Discussion options

You must be logged in to vote

hi -

when you're initializing your config, it isn't actually passed down to your dependencies in the current iteration - m is still:

	&Main{
		Config:     DefaultConfig(),
		DB:         data.NewDB(""),
		HTTPServer: http.NewServer(),
	}

from NewMain.

To fix your immediate problem, you'd at least want to pass the configured URI into your NewDB func:

m := &Main{}
m.ParseFlags()
// now, m.Config is populated
m.DB = data.NewDB(m.Config.db.uri)

However, I'd also think about maybe returning the Config object from ParseFlags and then constructing your components as needed:

cfg := ParseFlags()
m := &Main{
	DB: data.NewDB(cfg.db.uri),
	// other components initialized with `cfg` values
}

I hope tha…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@A2-NieR
Comment options

@stefanvanburen
Comment options

@A2-NieR
Comment options

@stefanvanburen
Comment options

Answer selected by A2-NieR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants