I'm facing a wierd problem with Golang.
On init() function, i want to assign a value to my variable that was declared outside this function.
But to assign the value to this var, i need to get
error
to check if everything is ok.
Here is the code:
var retryValue time.Duration
func init() {
retryValue, err := time.ParseDuration(retries)
if err != nil {
log.Fatal("retries value is invalid", err)
}
}
func a(){
fmt.Println(retryValue)
}
And i get the compiling error:
retryValue declared and not used
I need to change init() to this:
func init() {
var err error
retryValue, err = time.ParseDuration(retries)
if err != nil {
log.Fatal("retries value is invalid", err)
}
}
There is another way to solve this problem?
:=
always create a new variable if one of the variables are already declared? It's about variable golang's sope?
Thanks!