Reputation: 4781
I have read revel app.conf manual for custom configuration and environment variables. however I couldn't find way to use additional external configuration along with app.conf.
My goal is to achieve external configuration file in addition to internal app.conf. Let's say creating a product called example and example product maintains it's sensible defaults with app.conf (not exposing to end user) instead product exposes config attributes via example.conf (default location could be /etc/example/example.conf) for product users.
For example: http config field from app.conf
http.addr =
http.port = 9000
extend it to example.conf
http.addr =
http.port = 9000
[database]
host = "localhost"
port = 8080
user = "username"
password = "password"
# etc...
Then I read example.conf during an application start use values also apply values on top of app.conf (overriding). Finally revel server starts!
How to achieve this goal with revel go framework?
Upvotes: 1
Views: 748
Reputation: 2647
In github.com/revel/revel/revel.go around line 152 you have something like
Config, err = LoadConfig("app.conf")
.
Maybe you can try and modify that with this
if len(os.Getenv("SOME ENV VAR")) > 0 {
Config, err = LoadConfig("path/to/your/example.conf")
} else {
Config, err = LoadConfig("app.conf")
}
You just need to set env var on your prod server.
That way you will not be using app.conf but your example.conf.
Upvotes: 1
Reputation: 498
It appears you are working against the design of the app.conf. It is already setup to be sectioned, for example all this is in a single app.conf file
[dev]
results.pretty = true
watch = true
http.addr = 192.168.1.2
[test]
results.pretty = true
watch = true
http.addr = 192.168.1.22
[prod]
results.pretty = false
watch = false
http.addr = 192.168.1.100
you can launch 3 different scenarios by using three different command line options
revel run bitbucket.org/mycorp/my-app dev
revel run bitbucket.org/mycorp/my-app test
revel run bitbucket.org/mycorp/my-app prod
I know this is not exactly what your goal is but you can acheive a similar result.
Upvotes: 1