Skip to content

Strange behavior when working with pointer field #26

Description

@zhaoyao

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"

Activity

  1. fatih commented on Sep 8, 2015

    @fatih
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions