Closed anarcat closed 7 years ago
On 2017-01-30 11:25:57, Strubbl wrote:
In config.go, why do you have all the empty returns?
Because we have to return something. :) The variable are defined in the function declaration. For example this:
func ReadConfig(configJSON string) (err error) {
Config, err = getConfig(configJSON)
return
}
Declares a ReadConfig
functions which takes configJSON
(a string) and
returns err
(an error).
The return call implicitely returns the variable declared in the
function definition (in this case, err
).
Can't they be left out?
No, unfortunately. Go wants you to be pretty explicit sometimes.
Maybe i am missing some knowledge about returns here.
Maybe you'd like to read this section:
https://golang.org/ref/spec#Return_statements
In particular, I'm using section #3 here.
I found the spec to be quite readable. :)
A. -- Prolétaires de tous les pays, qui lave vos chaussettes?
Thanks for explaining and the link to the explicit chapter.
glad to help! :) i only learned that stuff because others helped me as well :)
this is a followup to https://github.com/Strubbl/wallabag-stats/issues/1 - the first part is obviously to add the necessary code to wallabago.
i moved the code to a separate
config.go
file and also included bits that were previously intoken.go
because it feels it makes more sense there.this will obviously break wallabag-stats, but i will followup with a PR there soon.
in my app, the API change is minimal, i just had to do this:
looks better too!