-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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] config.Scan does not scan duration types for yaml #1857
Comments
#1749 json: cannot unmarshal string into Go struct field Config of type time.Duration. |
Is this bug still open? I am a first-time contributor can I take this? |
It's works with package config
import (
"time"
str2duration "github.com/xhit/go-str2duration"
)
type Duration time.Duration
type Config struct {
Loop Duration `json:"loop"`
}
// UnmarshalText implements the text unmarshaller method
func (x *Duration) UnmarshalText(text []byte) error {
name := string(text)
tmp, err := str2duration.Str2Duration(name)
if err != nil {
return err
}
*x = Duration(tmp)
return nil
} |
This is the same issue as the one linked by @kaisawind . Closing this in favour of that one. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
config.Scan does not scan duration types for yaml.
I have a struct that contains a time.Duration. I am trying to use config to Scan a yaml file into this struct.
I expect when using a value such as "1000s" it will create will fill the struct with a 1000 * time.Second. If I use config.Get("duration").Duration(0), I get my expected result.
When using config.Scan, I get the zero value.
How to reproduce the bug:
Yaml:
Go:
Output:
Environment:
go version go1.14 darwin/amd64
The text was updated successfully, but these errors were encountered: