2 Comments
Sep 18, 2023Liked by Phuong Le

Nice write-up. There is something I don't quite get: the Age and Name field are exported, so what prevents me from directly setting values without using the GreetingOption mechanism?

Expand full comment
author

That's a good point, but my focus is on using default parameters via functional options, so the main target is the function, not the struct.

Also, we keep greet() unexported and expose only Greeting(...Options), this way, clients are forced to use greet through Greeting with options, so the struct is just a data container :)

Expand full comment