Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ailisp opened this issue Dec 20, 2019 · 4 comments

Comments

@ailisp
Copy link

ailisp commented Dec 20, 2019

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

@lukasaron
Copy link

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.

@ailisp
Copy link
Author

ailisp commented May 28, 2020

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

@lukasaron
Copy link

lukasaron commented May 29, 2020

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

@makarchuk
Copy link

makarchuk commented Feb 24, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants