I'm Starting To Like This Configuration Pattern In Go

  Рет қаралды 18,925

Anthony GG

Anthony GG

Күн бұрын

Пікірлер: 61
@anthonygg_
@anthonygg_ 11 ай бұрын
► 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
@smhmayboudi
@smhmayboudi 11 ай бұрын
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
@chandler828
@chandler828 11 ай бұрын
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!
@theRealWhexy
@theRealWhexy 8 ай бұрын
After viewing your amazing video on the functional options pattern, I changed my builder pattern to that. And now I see this... 🤯
@digitalsparky
@digitalsparky 11 ай бұрын
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.)
@bertrodgers2420
@bertrodgers2420 11 ай бұрын
do you have an example of this please?
@cristophermoreno2290
@cristophermoreno2290 11 ай бұрын
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 !
@sweetphilly2
@sweetphilly2 11 ай бұрын
I would've thought you'd return a pointer for each "With" function
@neilcarrier1620
@neilcarrier1620 11 ай бұрын
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.
@GushchinAndrei
@GushchinAndrei 10 ай бұрын
Thanks Antony! That’s great approach!
@yotubecreators47
@yotubecreators47 11 ай бұрын
As usual no bullshit no crap only pure 💯 advanced knowledge 💯 thank you 🙏
@lidtopz
@lidtopz 11 ай бұрын
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.
@TheQxY
@TheQxY 10 ай бұрын
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.
@manee427
@manee427 11 ай бұрын
Happy new year Anthony and wish you all the Best!
@tunedmystic1
@tunedmystic1 11 ай бұрын
Happy New Year! 🎉
@tigranrostomyan9231
@tigranrostomyan9231 11 ай бұрын
Happy new year!!! Thank you for the video :) Also how do you manage environment variables? I feel like sometimes it can be too verbose
@whynot9963
@whynot9963 11 ай бұрын
Exactly what I needed. Awesome job as always 👏
@kushagragupta3734
@kushagragupta3734 11 ай бұрын
Happy New Year.... Great videos thanks for this.... Eagerly waiting for CAS series to be resumed.
@manofqwerty
@manofqwerty 10 ай бұрын
In Golang, is there a way to have a readonly prop on a struct or would you expose these using methods?
@pratiktiwari5689
@pratiktiwari5689 11 ай бұрын
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
@athinodorossgouromalliis9021
@athinodorossgouromalliis9021 10 ай бұрын
Nice one bringing oops patterns to golang 😅. But it is cleaner and fail safe. GG Antony
@bharadwajuday16
@bharadwajuday16 8 ай бұрын
Simply lovely...!!
@anyDimka
@anyDimka 11 ай бұрын
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!
@metaltyphoon
@metaltyphoon 11 ай бұрын
Agree. In C# land we tend to add the Builder() suffix on the method name to say you are getting a builder back.
@plaintext7288
@plaintext7288 11 ай бұрын
​@@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
@yotubecreators47
@yotubecreators47 11 ай бұрын
Anyhony GG as usual God of Golang
@thesupremecoder
@thesupremecoder 11 ай бұрын
Happy new year
@talesmasoero
@talesmasoero 11 ай бұрын
Hey Anthony, what’s the theme that you use?
@anthonygg_
@anthonygg_ 11 ай бұрын
Gruvbox
@jdawgforealz
@jdawgforealz 10 ай бұрын
Curious what this offers or using config flags/env vars? package ff is what I typically use.
@Laflamablanca969
@Laflamablanca969 11 ай бұрын
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?
@TheQxY
@TheQxY 10 ай бұрын
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.
@dranon0o
@dranon0o 11 ай бұрын
I will stick to the dependency injection pattern ¯\_(ツ)_/¯ I prefer to deal with an array of typed functions Happy new year Anthony
@themichaelw
@themichaelw 11 ай бұрын
How do you test code with dependency injection? Do you find yourself mocking things a lot?
@alexIVMKD
@alexIVMKD 11 ай бұрын
Good stuff
@thegittubaba
@thegittubaba 11 ай бұрын
It feels nice. But with each With call, we leave behind a orphaned struct to be garbage collected. That kinda irks me.
@fsra16
@fsra16 11 ай бұрын
Does using pointer receivers solve this?
@thegittubaba
@thegittubaba 11 ай бұрын
@@fsra16 That would be a slightly different pattern. WithName function becomes SetName. Then you chain multiple SetFoo calls.
@MegaMage79
@MegaMage79 11 ай бұрын
Wouldn't go usually allocate those intermediary Configs on the stack ?
@anthonygg_
@anthonygg_ 11 ай бұрын
I think its allocated on the stack to be honest. Why would it not be?
@thegittubaba
@thegittubaba 11 ай бұрын
@@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.
@demyk214
@demyk214 10 ай бұрын
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_
@crusader_ 7 ай бұрын
What font are you using?
@anthonygg_
@anthonygg_ 7 ай бұрын
Consolas
@mrcth6593
@mrcth6593 11 ай бұрын
good sht!!#
@ThangTran-hi3es
@ThangTran-hi3es 11 ай бұрын
First video of 2024 right 😅😅
@pseabrook
@pseabrook 11 ай бұрын
Good video but when are you starting a dating advice channel?
@demyk214
@demyk214 10 ай бұрын
Spouwn😂
@vitiok78
@vitiok78 11 ай бұрын
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
@mitrabeast
@mitrabeast 11 ай бұрын
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_
@anthonygg_ 11 ай бұрын
😂
@nixoncode
@nixoncode 11 ай бұрын
sorry to see you go!
@mitrabeast
@mitrabeast 11 ай бұрын
@@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-ai
@perc-ai 11 ай бұрын
@@mitrabeast ur just a crud developer lol learn some real skills kid
@mitrabeast
@mitrabeast 11 ай бұрын
@@perc-ai Huh? If you were an experienced developer, you could simply answer my question in a comment, without mentioning your psychological problem.
@jaymartinez311
@jaymartinez311 11 ай бұрын
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 🫡
Another Amazing Use Case For The FOP Pattern In Go
4:10
Anthony GG
Рет қаралды 10 М.
This Will Make Everyone Understand Golang Interfaces
21:03
Anthony GG
Рет қаралды 55 М.
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
Why is Python 150X slower than C?
10:45
Mehul - Codedamn
Рет қаралды 27 М.
Golang Channels Or Wait Groups? Let Me Explain.
18:32
Anthony GG
Рет қаралды 26 М.
The Most Efficient Struct Configuration Pattern For Golang
11:10
Go application setup with PostgreSQL, sqlx, goose migrations
9:38
Make Programming Fun Again
Рет қаралды 8 М.
How To Setup A Golang + Templ Project Structure
31:20
Anthony GG
Рет қаралды 55 М.
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 101 М.
Not a Single Line of JavaScript has Been Written??
7:05
Anthony GG
Рет қаралды 13 М.
Mastering Dependency Injection In Golang
14:29
Anthony GG
Рет қаралды 52 М.
Unboxing the Raspberry Pi CM5 Development Kit
11:36
Level 2 Jeff
Рет қаралды 47 М.
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН