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

Strange behavior when working with pointer field #26

Open
zhaoyao opened this issue Sep 8, 2015 · 1 comment
Open

Strange behavior when working with pointer field #26

zhaoyao opened this issue Sep 8, 2015 · 1 comment
Labels

Comments

@zhaoyao
Copy link

zhaoyao commented Sep 8, 2015

Test code

package main

import "github.com/koding/multiconfig"
import "os"
import "time"

type duration struct {
    time.Duration
}

func (d *duration) UnmarshalText(text []byte) error {
    var err error
    d.Duration, err = time.ParseDuration(string(text))
    return err
}

type A struct {
    //B *duration `default:"10s"`

    // works as expected
    B *duration `toml:"b"`
}

func main() {
    a := &A{}
    multiconfig.MustLoadWithPath(os.Args[1], a)
    println(a.B.String())
}

When specify argument value through env or cli args for pointer type, will cause multiconfig compain "not support type: ptr"

@fatih
Copy link
Contributor

fatih commented Sep 8, 2015

Hi @zhaoyao. Thanks for the excellent bug. I found the issue and it's due the TagLoader. However if you would trigger the EnvLoader with something like A_B=12s go run demo.go b.toml you would again get the same error.

The underlying problem is, the TOML loader uses the TOML package to unmarshal your file on top of the struct. That package has no problem with it and deals good with pointer to float64 (time.Duration type).

But we use a custom field setter (fieldSet function), and that particular function doesn't support pointer to types yet. It can be fix indeed and we are going to look at it. Thanks again for the bug report, much appreciated!

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

No branches or pull requests

2 participants