► Join my Discord community for free education 👉 discord.com/invite/Ac7CWREe58 ► Exclusive Lessons, Mentorship, And Videos 👉 www.patreon.com/anthonygg_ ► 60% OFF on my Golang course 👉 fulltimegodev.com Thanks for watching
@smhmayboudi11 ай бұрын
Hi Anthony GG, Thanks in advanced for your contribution on Go Community. This is the Builder Pattern. You are comparing the Config Struct and the Functional One. I did this in a project and I find out it is not well suited for big complex configs. In my case, there are separation code of multiple product with multiple service which done by directory and build tags. In addition, I have a suite test controller which separately run a test case for unit test and integration test. After a while I find some of configuration elements are missed on tests, so some of tests with the incorrect configs are passed. I understand every test should be very careful crafted by hand and mind, however there are times which we have rush. My prefare for configuration to have a basic classes which construct in main by external library (reading from yaml, toml or env). In addition, I engaged with envoy and they have a different approach which I think I should investigate. Using proto as a config manager. AGAIN MANY THANKS
@chandler82811 ай бұрын
Anthony GG with another absolute banger of a video. I love these go pattern videos. I’ve implemented functional parameters at work and in my personal side project. This, in my opinion, takes it a step further. You are decoupling your service, or object, from the configuration specification. There are pros and cons to both approaches. Just another tool in your tool belt!
@theRealWhexy8 ай бұрын
After viewing your amazing video on the functional options pattern, I changed my builder pattern to that. And now I see this... 🤯
@digitalsparky11 ай бұрын
I very much prefer the chaining pattern. I've used it in a number of languages, most recently PHP, and it works fantastically well there. (yes, I know, in some circles PHP is a dirty language, but as far as I see it, they're all tools for a job, not a religious ideology, if you get what I mean.)
@bertrodgers242011 ай бұрын
do you have an example of this please?
@cristophermoreno229011 ай бұрын
I am starting this year strong, so. you have a new patron today ! Thank you for sharing your knowledge GG on Go.Happy new year !
@sweetphilly211 ай бұрын
I would've thought you'd return a pointer for each "With" function
@neilcarrier162011 ай бұрын
The main difference may be the amount of control needed by users of the API: If you want the users to have control over the configuration, functional options is good, because they can write their own functions. If you want to lock down the configuration, use chaining with private member values. But always, as Anthony emphasizes, do what is most clear and simple for users and maintainers in the particular instance.
@GushchinAndrei10 ай бұрын
Thanks Antony! That’s great approach!
@yotubecreators4711 ай бұрын
As usual no bullshit no crap only pure 💯 advanced knowledge 💯 thank you 🙏
@lidtopz11 ай бұрын
Happy new years all! I think the major drawback is you are revoking the user's power to creating their own option functions, if they are reusing your func a lot and want a stable configuration function that applies what they want to the struct.
@TheQxY10 ай бұрын
Interesting. Not certain if I prefer it over the functional options pattern or not. It easier to implement, but I think the functional options pattern creates a API which I think most Go users are more familiar with, so I don't necessarily think this is more clear.
@manee42711 ай бұрын
Happy new year Anthony and wish you all the Best!
@tunedmystic111 ай бұрын
Happy New Year! 🎉
@tigranrostomyan923111 ай бұрын
Happy new year!!! Thank you for the video :) Also how do you manage environment variables? I feel like sometimes it can be too verbose
@whynot996311 ай бұрын
Exactly what I needed. Awesome job as always 👏
@kushagragupta373411 ай бұрын
Happy New Year.... Great videos thanks for this.... Eagerly waiting for CAS series to be resumed.
@manofqwerty10 ай бұрын
In Golang, is there a way to have a readonly prop on a struct or would you expose these using methods?
@pratiktiwari568911 ай бұрын
Hi Anthony can you suggest some intermediate and advanced open source projects from where you learn all these things where maybe I can learn new stuff and contribute in golang
@athinodorossgouromalliis902110 ай бұрын
Nice one bringing oops patterns to golang 😅. But it is cleaner and fail safe. GG Antony
@bharadwajuday168 ай бұрын
Simply lovely...!!
@anyDimka11 ай бұрын
The only confusion I have here is that when I invoke function that starts with "New", I expect to receive a pointer to the structure. However, this pattern is quite popular and is widely used in the MongoDB library. Thanks for the content and Happy New Year!
@metaltyphoon11 ай бұрын
Agree. In C# land we tend to add the Builder() suffix on the method name to say you are getting a builder back.
@plaintext728811 ай бұрын
@@metaltyphoon Adding a builder type in Go doesn't seem to be as bad of an idea. It could probably be something like: type Config struct { ListenAddr string Unspecified string } type ConfigBuilder [string] interface{} func (cb *ConfigBuilder) WithListenAddr (listenAddr string) *ConfigBuilder { cb["listenAddr"] = listenAddr return cb } func (cb ConfigBuilder) Build() *Config, { var conf Config if listenAddr, ok := cb["listenAddr"]; ok { conf.ListenAddr = listenAddr.(string) } else { conf.ListenAddr = ":3000" } if unspecified, ok := cb["unspecified"]; ok { conf.Unspecified = unspecified.(string) } else { conf.Unspecified = "foobar" } return conf } The code seems a little too much, but it guarantees that the config used has all the values initialized. Tests for the builder are a must to ensure valid types in the map Also, for testing, it will likely need util functions to initialize a basic test config which do all the builder stuff Edit: typos, formatting
@yotubecreators4711 ай бұрын
Anyhony GG as usual God of Golang
@thesupremecoder11 ай бұрын
Happy new year
@talesmasoero11 ай бұрын
Hey Anthony, what’s the theme that you use?
@anthonygg_11 ай бұрын
Gruvbox
@jdawgforealz10 ай бұрын
Curious what this offers or using config flags/env vars? package ff is what I typically use.
@Laflamablanca96911 ай бұрын
Is there a reason why you wouldn’t just store the config in the server and access it that way? Rather than doubling up on the fields in config and server?
@TheQxY10 ай бұрын
With this pattern it wouldn't make much of a difference I guess. But it makes it more clear which field are set by client input and which fields are inherent to the server implementation.
@dranon0o11 ай бұрын
I will stick to the dependency injection pattern ¯\_(ツ)_/¯ I prefer to deal with an array of typed functions Happy new year Anthony
@themichaelw11 ай бұрын
How do you test code with dependency injection? Do you find yourself mocking things a lot?
@alexIVMKD11 ай бұрын
Good stuff
@thegittubaba11 ай бұрын
It feels nice. But with each With call, we leave behind a orphaned struct to be garbage collected. That kinda irks me.
@fsra1611 ай бұрын
Does using pointer receivers solve this?
@thegittubaba11 ай бұрын
@@fsra16 That would be a slightly different pattern. WithName function becomes SetName. Then you chain multiple SetFoo calls.
@MegaMage7911 ай бұрын
Wouldn't go usually allocate those intermediary Configs on the stack ?
@anthonygg_11 ай бұрын
I think its allocated on the stack to be honest. Why would it not be?
@thegittubaba11 ай бұрын
@@anthonygg_ Yeah seems like it would actually be allocated on stack, after taking a quick look at go spec, it'll only be in heap if size doesn't fit. Also config/options are normally set only once at start of a server/big operation so I guess its even more inconsequential.
@demyk21410 ай бұрын
Anthony ik weet niet of het yt. Maar doe is koptelefoon op. Geluid is slechter dan door de koptelefoons (3 getest van sony & jbl boven 200 euro) dan door de speakers ben je echt glashelder. Misschien goed om te weten man.
@crusader_7 ай бұрын
What font are you using?
@anthonygg_7 ай бұрын
Consolas
@mrcth659311 ай бұрын
good sht!!#
@ThangTran-hi3es11 ай бұрын
First video of 2024 right 😅😅
@pseabrook11 ай бұрын
Good video but when are you starting a dating advice channel?
@demyk21410 ай бұрын
Spouwn😂
@vitiok7811 ай бұрын
So... If I'm not mistaken you've just reinvented the typical object-oriented approach with class that has private properties and a bunch of fluent setters. It is basics in object-oriented world
@mitrabeast11 ай бұрын
This is the worst... Watched because of some recommendations, unsubscribed... Why do you need to make everything more complex these days? Just use some public structure fields
@anthonygg_11 ай бұрын
😂
@nixoncode11 ай бұрын
sorry to see you go!
@mitrabeast11 ай бұрын
@@nixoncode It's not that I put some value in unsubing but the fact that I'm not interested in this kind of content. Just to make sure it won't be mentioned in the comment answers. Nobody including the author gave the answer why do you actually need to complicate things. Just a haughty laughing emoji instead. Very professional response.
@perc-ai11 ай бұрын
@@mitrabeast ur just a crud developer lol learn some real skills kid
@mitrabeast11 ай бұрын
@@perc-ai Huh? If you were an experienced developer, you could simply answer my question in a comment, without mentioning your psychological problem.
@jaymartinez31111 ай бұрын
Happy new year. After abandoning rust because i hated how it mutated state i’m back at golang. I was a bit frustrated at first because it was missing a lot of built in functions but i started building my own utility functions & like your video i think its making me a better programmer 🫡