Go (Golang) Functional Options Pattern
HTML-код
- Опубликовано: 4 ноя 2024
- Go (Golang) Functional Option Design Pattern
The Functional Options pattern is pretty useful when building Go packages that need to be configured with different and varying configuration options. One of the ways you could configure that is by using a Config struct or some other pre-defined package level structs. Although that works it's not as elegant and robust as the Functional Option pattern which allows you to build countless extensions to your package functionality without breaking its public APIs (method definition and interfaces)
Source Code - play.golang.or...
💼 Golang Cafe - golang.cafe
📬 Golang Cafe Jobs Newsletter - golang.cafe/ne...
🐦 Golang Cafe Twitter - / golangcafe
📣 Telegram Channel - t.me/golangcafe
🙏 Found this video useful? Help me make more by donating $5.00 - golang.cafe/5USD
So cool
Very clear thanks 👍
This is beautiful! I should create a design pattern series as well. Love your channel, you always talk about things that I often overlook from my day job :)
Thanks!
Great pattern.
I want to emphasize to define the `Option` type. So on godoc, all functional options are grouped under `Option` type.
Thanks!
Nice clear explanation.
thnaks for this. learning day by day with your videos.
I am glad to hear this, thanks for watching!
Came for Go, stayed for VIM.. you must do a video on your vim setup
What are the advantages and disadvantages over builder pattern? 🤔 Cause you know we are using closures in here which are technically objects which have state + a method for closure call, so why not put those states in builder object? Oh I see, this one is more dynamic, we can compose different options array at runtime, it requires another layer or something to do it in builder pattern... It was nice then :)
I didn’t get it at first. But then I liked and subscribed. Clever, but in a good way.
great idea!
So cool, man!
Thank you! I am glad you liked it
great video
Thanks for watching!