Introduction
Hello, everyone! 😉 Today, I would like to discuss about configuration for web application on Golang. And not just talk, but...
For further actions, you may consider blocking this person and/or reporting abuse
I truly appreciate the contribution to the community. That said though, as this feels targeted at newcomers, I personally wouldn't teach "global variables" or "using the init()" function if I could avoid it. Later in life, those two constructs make it harder to test and much harder to find a certain class of bugs, especially when the code base gets a lot bigger. Feel free to ignore me though lol, just my $0.02.
Didn't really understand, when
init()
became an anti-pattern for the Go community? Give me a link to an article about it, please. Same thing about "global variables".Maybe you should write the right article about how to make a Go web app config in the right format? I'd read it, really.
I don't have the slightest idea what you're talking about here. Explain, please. I haven't even met you to ignore you. 🤷♂️
Rather than duplicating the work, I'll just give you an MR on your repo with reference :)
As far as ignoring me, I'm opinionated, so it comes with the territory lol.
Oh, that's would be nice! Thx 😉
But, actually, when
init()
become an "anti-pattern"? Because I seeinit()
on many online books, courses and articles by Go bloggers.I googled it, but I couldn't find any confirmation of your words.
Even the other way around! For example, "Effective Go" book on official Golang website: golang.org/doc/effective_go.html#init
Good article, thank you. I'm working on a personal project and using this opportunity to learn go. I followed your guide mostly, except I have two different configuration files. I wanted to avoid rewriting code, and I was able to abstract away the type of config struct from the YML parsing function using an
interface{}
as an additional parameter. It worked well for me, you can see it here. Thanks again.Thanks for reply! 😉 Yep, separated configs are very helpful.
Interesting project, btw! Keep going 👍
Thanks for this article! It helped me to learn some Go.
Is there any way to set required fields in the config?