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

bug: []time.Duration not works #39

Open
ergoz opened this issue Dec 8, 2022 · 5 comments
Open

bug: []time.Duration not works #39

ergoz opened this issue Dec 8, 2022 · 5 comments

Comments

@ergoz
Copy link

ergoz commented Dec 8, 2022

Example struct

type MyStruct struct {
    BackoffPolicy []time.Duration `default:"...."`
}

Checked variants:

  • default:"{[\"10s\",\"1m\"]}"
  • default:"[\"10s\",\"1m\"]"
  • default:"[10s,1m]"
  • default:"\"10s\",\"1m\""
  • default:"10s,1m"

all of them not works

@creasty
Copy link
Owner

creasty commented Dec 8, 2022

An underlying type of time.Duration is int64.
Therefore, you need to specify integer values (in nanoseconds) such that:

type MyStruct struct {
    BackoffPolicy []time.Duration `default:"[10000000000,60000000000]"` // 10s, 1m
}

#32 might be what you're looking for — pull requests are welcome.

@creasty creasty closed this as completed Dec 8, 2022
@ergoz
Copy link
Author

ergoz commented Dec 8, 2022

Here - https://github.com/creasty/defaults/blob/master/defaults.go#L86 code is trying to parse string and in test file i can find

Duration  time.Duration `default:"10s"`

https://github.com/creasty/defaults/blob/master/defaults_test.go#L48

What made me confused that in slice i need to change behavior)))

@ergoz ergoz closed this as completed Dec 8, 2022
@creasty
Copy link
Owner

creasty commented Dec 9, 2022

Here - https://github.com/creasty/defaults/blob/master/defaults.go#L86 code is trying to parse string and in test file i can find

Ahhh...
Thanks, I'll fix that test code later!

@yuyang0
Copy link

yuyang0 commented Aug 19, 2023

@creasty using int64 to specify Duration is very ugly. string representation of duration is very useful in config file.

@creasty
Copy link
Owner

creasty commented Aug 21, 2023

Sorry for the oversight!
Reading over the discussion again, I recognize that I missed the point.
I had a lapse in memory regarding supporting the string representation of Duration, leading to my assumption that it never worked.

@creasty creasty reopened this Aug 21, 2023
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