Go Config is a simple package that allows to load basic data for a Golang application.
It supports toml
, json
, yaml
or xml
file or content to instantiate environment variables.
Before to run application you may setup a supportedconfig.toml
with Config
values.
Check out the following tables to know all Config
parameters detailed.
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
environment |
Website environment. | string |
|
YES |
service |
Website service identifier as string. | string |
|
YES |
[server] |
Http server config data. | Server |
|
YES |
[token] |
Token data config data. | Token |
|
YES |
[mongodb] |
Postgres database config data. | Database |
|
YES |
[mysql] |
MySql database config data. | Database |
|
YES |
[postgres] |
Postgres database config data. | Database |
|
YES |
[audit] |
Auditing options config data. | Audit |
|
YES |
[tracer] |
Tracing options config data. | Tracer |
|
YES |
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
host |
HTTP server host name. | string |
|
YES |
port |
HTTP server port number. | int |
|
YES |
allowed_origins |
Allowed hosts to CORS allowance. | []string |
|
NO |
To set up [mysql]
and [postgres]
use the following parameters:
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
db |
Database name. | string |
|
YES |
host |
Database host. | string |
|
YES |
migrations_path |
Migrations directory path. | string |
file://migrations/<mongo><mysql><postgres> |
NO |
password |
Database password. | string |
|
YES |
port |
Database port. | int |
|
YES |
user |
Database user with needed privileges over database. | string |
|
YES |
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
secret |
Website token secret string. | string |
|
YES |
max_age |
Maximum duration of a token (in seconds). | int |
86400 |
NO |
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
Enable |
Enable flag to activate auditing. | bool |
FALSE |
NO |
Host |
Auditing server host address. | string |
|
NO |
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
Enable |
Enable flag to activate tracing. | bool |
FALSE |
NO |
JaegerHost |
** Deprecated ** Jaeger host address. | string |
http://localhost:14268/api/traces |
NO |
Host |
Tracer host address. | string |
|
NO |
First you need to get dependency go_config
dependency by calling go get
, with the wanted release.
go get github.com/ribeirohugo/go_config@latest
Then, data can be loaded by calling Load
method.
It supports a config.toml
file properly fulfilled.
cfg, err := toml.Load(configFile)
if err != nil {
log.Fatal(err)
}
It will return a config.Config
struct variable or an error, if anything unexpected occurs.
Then, data can be loaded by calling Load
method, with a config.yaml
file properly fulfilled.
cfg, err := yaml.Load(configFile)
if err != nil {
log.Fatal(err)
}
It will return a config.Config
struct variable or an error, if anything unexpected occurs.
Then, data can be loaded by calling Load
method, with a config.json
file properly fulfilled.
cfg, err := json.Load(configFile)
if err != nil {
log.Fatal(err)
}
It will return a config.Config
struct variable or an error, if anything unexpected occurs.
Then, data can be loaded by calling Load
method, with a config.json
file properly fulfilled.
cfg, err := xml.Load(configFile)
if err != nil {
log.Fatal(err)
}
It will return a config.Config
struct variable or an error, if anything unexpected occurs.