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

Durations don't work in viper.Marshal #105

Closed
kelvl opened this issue Jul 31, 2015 · 3 comments
Closed

Durations don't work in viper.Marshal #105

kelvl opened this issue Jul 31, 2015 · 3 comments

Comments

@kelvl
Copy link

kelvl commented Jul 31, 2015

Hi, I am unable to Marshal (or Unmarshal) Duration fields whereas, GetDuration("fieldName") works

I've attached an simple test case

package main

import (
    "bytes"
    "testing"
    "time"

    "github.com/spf13/viper"
)

func TestDurationConfig(t *testing.T) {
    type DurationConfig struct {
        testduration time.Duration
    }

    var testYaml = []byte(`
               TestDuration: 5ms
        `)

    viper.SetConfigType("yaml")

    viper.ReadConfig(bytes.NewBuffer(testYaml))

    t.Logf("All keys: %#v", viper.AllSettings())

        // this works
    if viper.GetDuration("testduration") != 5*time.Millisecond {
        t.Errorf("Duration is not 5ms - %v", viper.GetDuration("testduration"))
    }

    var config = &DurationConfig{}

    viper.Marshal(config)

        // this doesn't
    if config == nil || config.testduration != 5*time.Millisecond {
        t.Errorf("Duration config is not 5ms - %#v", config)
    }
}
@emilevauge
Copy link

Any chance to get this bug corrected?

@ondrajz
Copy link

ondrajz commented Feb 7, 2016

+1

@yauhen-l
Copy link
Contributor

yauhen-l commented Jul 9, 2016

I've suggested fix: #205

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

4 participants