gurkankaymak / hocon

go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config
MIT License
79 stars 17 forks source link

Optional system or env variable overrides #8

Closed egorlepa closed 2 years ago

egorlepa commented 3 years ago

https://github.com/lightbend/config#optional-system-or-env-variable-overrides Override feature is not implemented.

CASE 1

go {
  path = "/whatever/whatever"
  path = ${?GOPATH}
}

config.GetString("go.path") // returns /Users/egorlepa/go as it should

CASE 2

go {
  path = "/whatever/whatever"
  path = ${?NON_EXISTENT_ENV}
}

config.GetString("go.path") // returns ${?NON_EXISTENT_ENV}

Case 2 should return /whatever/whatever, because:

the override field basedir = ${?FORCED_BASEDIR} simply vanishes if there's no value for FORCED_BASEDIR, but if you set an environment variable FORCED_BASEDIR for example, it would be used.
gurkankaymak commented 2 years ago

fixed with #13

fredrikjacobson commented 2 years ago

Is there a release pending for this fix?

gurkankaymak commented 2 years ago

@fredrikjacobson published a release for the fix https://github.com/gurkankaymak/hocon/releases/tag/v1.2.4

fredrikjacobson commented 2 years ago

@fredrikjacobson published a release for the fix https://github.com/gurkankaymak/hocon/releases/tag/v1.2.4

Thanks!

When trying it out it looks like there some issue happening when used in conjunction with withFallback. God null reference error when doing that

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x14d7e30]

goroutine 1 [running]:
github.com/gurkankaymak/hocon.mergeObjects(0x15c78c0, 0xc00035fa60)
        /Users/fredrikjacobson/go/pkg/mod/github.com/gurkankaymak/hocon@v1.2.4/parser.go:376 +0xd0
github.com/gurkankaymak/hocon.mergeObjects(0x100c027, 0x14)
        /Users/fredrikjacobson/go/pkg/mod/github.com/gurkankaymak/hocon@v1.2.4/parser.go:378 +0x135
github.com/gurkankaymak/hocon.(*Config).WithFallback(0xc0000285d0, 0xf)
        /Users/fredrikjacobson/go/pkg/mod/github.com/gurkankaymak/hocon@v1.2.4/config.go:266 +0x57
gurkankaymak commented 2 years ago

hi @fredrikjacobson, this should be the same case with #15 , it is fixed with the latest commit, if you are still getting this error please provide a sample config

fredrikjacobson commented 2 years ago

Yes that did the trick for using withFallback.