kelseyhightower / envconfig

Golang library for managing configuration data from environment variables
MIT License
5.07k stars 382 forks source link

[IMPORTANT!] Commit broke parsing compatibility #54

Closed marcosnils closed 8 years ago

marcosnils commented 8 years ago

Hi, this use case was working before commit 31176c57a5eacded4755c5f9eac8eb5a603cfbfd

package main

import (
    "fmt"
    "net/url"
    "os"

    "github.com/kelseyhightower/envconfig"
)

type Config struct {
    One string `envconfig:"one"`

    WebUrl *url.URL

    Two string `envconfig:"two"`
}

func main() {

    os.Setenv("TEST_ONE", "one")
    os.Setenv("TEST_TWO", "two")

    c := Config{}

    envconfig.Process("test", &c)
    fmt.Println(c.One)
    fmt.Println(c.Two) // two should be parsed and it's not

}

@elgris @teepark @kelseyhightower :bell:

marcosnils commented 8 years ago

@teepark I found another issue with the same commit. If a struct implements the Decode function it won't be called because the introduced code will try to parse the struct internally instead of using the proper Decode function.

Even though I can provide a fix, I'm not sure how you want this to work but it's currently breaking backwards compatibility.

Example:

package main

import (
    "fmt"
    "os"

    "github.com/kelseyhightower/envconfig"
)

type TestDecode struct {
    Value string
}

func (t *TestDecode) Decode(env string) error {
    t.Value = "Some value"
    return nil
}

type Config struct {
    Test TestDecode `envconfig:"decode"`
}

func main() {

    os.Setenv("TEST_DECODE", "one")

    c := Config{}

    envconfig.Process("test", &c)

    fmt.Println(c.Test.Value) // Should print "Some Value"

}

This was working before the mentioned commit @elgris @kelseyhightower