OS variables not working on configuration data
Closed this issue · 3 comments
this is an awesome go package. But I have trouble when using the OS variable on my configuration data. I am using go 1.14.
I have db.json
with some data below:
{"name": "MyApp", "port": "${ APP_PORT }"}
From my go code
v, err := c.Get("port") // just return ${ APP_PORT } for the v
so I get v with value ${ APP_PORT }, not the exact value of OS.Getenv("APP_PORT").
fmt.Println(v) // ${ APP_PORT }
I tested your sample using Go v1.14 but it worked. Please see this attachment:
Sample.zip
If you still sure it works that way please attach your code.
Nice, everything works perfectly. It doesn't work when using feeder.JsonDirectory{Path: "./config"}.
I change the code a little bit from Sample.zip:
I make .env
and a config folder to store all the configs from the root folder config
|- main.go
|- .env
|- go.mod
|- config
|-- c.json
from .env
APP_PORT=8080
func main() {
c, err := config.New(config.Options{
Feeder: feeder.JsonDirectory{Path: "./config"},
Env: ".env",
})
if err != nil {
panic(err)
}
v, err := c.Get("c.port")
fmt.Println(v, err) // it prints ${ APP_PORT } <nil>
}
What am I missing?
This bug is fixed now. Thanks for your report.
New release:
https://github.com/golobby/config/releases/tag/v1.0.4