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

OS variables not working on configuration data #4

Closed
akbarpn136 opened this issue Mar 20, 2020 · 3 comments
Closed

OS variables not working on configuration data #4

akbarpn136 opened this issue Mar 20, 2020 · 3 comments

Comments

@akbarpn136
Copy link

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 }

@miladrahimi
Copy link
Member

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.

@akbarpn136
Copy link
Author

akbarpn136 commented Mar 21, 2020

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?

@miladrahimi
Copy link
Member

This bug is fixed now. Thanks for your report.
New release:
https://github.com/golobby/config/releases/tag/v1.0.4

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

No branches or pull requests

2 participants