|
|
|
|
|
by TheDong
2756 days ago
|
|
Note that your code will not work; you've shadowed 's' inside the if block because you have 'if s, err := ...'. As a result, 's = defaults()' will set the shadowed 's' variable that only exists within the if block to defaults, but the 'var s Settings' you declared above will not be modified. Here's a playground showing the issue: https://play.golang.org/p/eE0HEZx1MJu Go is full of nice little foot-guns like that :) You would want to also have 'var err error' above the block and use '=' instead of ':=' to fix this sort of issue. |
|