-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
unmarshal string into time.Duration #201
Comments
The same issue: package main
import (
"fmt"
"time"
"github.com/goccy/go-yaml"
)
type Config struct {
Batching Batching `yaml:"batching"`
}
type Batching struct {
Timeout time.Duration `yaml:"timeout"`
Limit int `yaml:"limit"`
}
func main() {
sample := `
batching:
timeout: 1s
limit: 200
`
var b Config
if err := yaml.Unmarshal([]byte(sample), &b); err != nil {
panic(err)
}
fmt.Printf("%+v", b)
} Results in:
|
quentinmit
added a commit
to quentinmit/go-yaml
that referenced
this issue
Aug 11, 2021
This uses `time.ParseDuration` and `time.Duration.String`, and is compatible with gopkg.in/yaml's encoding.
goccy
added a commit
that referenced
this issue
Aug 25, 2021
Encode and decode time.Duration fields (#201)
The latest version parses this case correctly, see https://play.golang.org/p/aH8Pmd4QnMe @goccy should be this issue closed? |
@franchb Yes ! Thank you for notification ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would it be possible to get support for unmarshalling strings into a time.Duration variable (such as
10h
/10h30m
etc..)Thanks
The text was updated successfully, but these errors were encountered: