Are you one of the many coders who find it annoying that Go doesn't have default parameter values? If that's the case, you're far from being the only one.
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?
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 :)
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?
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 :)