when u64 config has non zero default and zero in config, config has no effect
ailisp opened this issue · comments
Having this as part of my config:
IdleMachines uint64 `yaml:"idle_machines" default:"2"`
and in config.yaml if it's
idle_machines: 3
It has effect
But in config.yaml if it's
idle_machines: 0
There's no effect and IdleMachines is still 2
This behavior is correct and expected to work this way. When you provide a value in your config.yaml
file such value has the higher priority then default tag in the code. When you remove the line from your config.yaml
you should be able to get the default value, in this case number 2.
This behavior is correct and expected to work this way. When you provide a value in your config.yaml file such value has the higher priority then default tag in the code. When you remove the line from your config.yaml you should be able to get the default value, in this case number 2.
Actually not, I'm not remove the idle_machines:
line, instead I set it to idle_machines: 0
, so as you point out, idle_machines: 0
in config.yml should take have higher priority over:
IdleMachines uint64 `yaml:"idle_machines" default:"2"`
But finaly idle_machines is 2, means it's not true
I have tested locally your issue and I can't reproduce it, to be honest.
I will paste the whole code I used:
config.yaml:
idle_machines: 0
main.go:
import (
"fmt"
"github.com/jinzhu/configor"
"log"
)
type Config struct {
IdleMachines uint64 `yaml:"idle_machines" default:"2"`
}
func main() {
var config Config
err := configor.Load(&config,"<ABSOLUTE_PATH_TO_THE_FILE>/config.yaml")
if err != nil {
log.Fatal(err)
}
fmt.Println(config.IdleMachines)
}
Result: 0
I believe this is a duplicate of #34 and has been fixed already