configor icon indicating copy to clipboard operation
configor copied to clipboard

when u64 config has non zero default and zero in config, config has no effect

Open ailisp opened this issue 5 years ago • 4 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

ailisp avatar Dec 20 '19 07:12 ailisp

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.

lukasaron avatar May 28 '20 08:05 lukasaron

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

ailisp avatar May 28 '20 17:05 ailisp

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

lukasaron avatar May 29 '20 09:05 lukasaron

I believe this is a duplicate of #34 and has been fixed already

makarchuk avatar Feb 24 '21 09:02 makarchuk