If you want to make a config file for development, testing, staging and production, I would recommend to use the // +build
possibility offered by Go.
Set up your Go program
You create 4 files in a config
packages as followed :
src/program/config
|
|--config_dev.go
|--config_test.go
|--config_staging.go
|--config_prod.go
In the config files
Then in each file, you define the tag used to use that file during the go build
(or run, ...) process.
It means for instance in config_dev.go :
// +build dev
package config
// Development ready configuration const based on the build tags.
const (
MYSETTINGS = "dev blablabla"
ISREADY = false
)
In the config_test.go, that would look like :
// +build test
package config
// Development ready configuration const based on the build tags.
const (
MYSETTINGS = "test blablabla"
ISREADY = true
)
Note the // +build dev
and // +build test
.
That are the tags you are going to use during build to tell which config file you want to use.
In any other Go file, you just have to call config.ISREADY
without importing anything else that "config"
in your file.
Build
Then to build your app, you just have to run :
go build -tags dev
to build with the development config
or
go build -tags test
to build with the testing config.