redability
Optional Parameters Using Option Struct
· ☕ 5 min read
Introduction In last post we learned how we can use functional options to pass parameter to our functions. In this post we’ll see an alternative way to do the same thing. I’ll take the same code from the last post to keep things simple. Variadic Functions for Options 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 type Coffee struct { CoffeeBeans bool Sugar bool SteamedMilk bool } func New(opts .

Optional Parameters using Functional Options
· ☕ 5 min read
Introduction In Python you can assign default value to the functions, like so: 1 2 def my_func(posarg, named_arg=True, another_named_arg="Okay") # logic goes here... But in Go you can’t do this: 1 2 3 func myFunc(posarg, named_arg bool = true, another_named_arg string = "Okay") { // logic goes here... } This will throw a syntax error. Try that? In this post, we’ll see how can we overcome this issue the go way, with something called Function Options.