good morning!!!!

Skip to content
Snippets Groups Projects
Commit a2e4a9ca authored by a's avatar a
Browse files

support environmental variables reaplcement through

parent 64d49c8d
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ pools:
port: 5432
role: primary
username: postgres
password: example
password: ENV$PGGAT_DB_PASS
sharded:
pool_mode: transaction
default_role: any
......
......@@ -3,8 +3,10 @@ package config
import (
"os"
"path/filepath"
"strings"
"github.com/BurntSushi/toml"
"github.com/davecgh/go-spew/spew"
"gopkg.in/yaml.v3"
)
......@@ -52,6 +54,31 @@ func Load(path string) (*Global, error) {
return nil, err
}
}
for _, g := range g.Pools {
for _, shard := range g.Shards {
for _, srv := range shard.Servers {
if strings.HasPrefix(srv.Host, "ENV$") {
srv.Host = os.Getenv(strings.TrimPrefix(srv.Host, "ENV$"))
}
if strings.HasPrefix(srv.Username, "ENV$") {
srv.Username = os.Getenv(strings.TrimPrefix(srv.Username, "ENV$"))
}
if strings.HasPrefix(srv.Password, "ENV$") {
srv.Password = os.Getenv(strings.TrimPrefix(srv.Password, "ENV$"))
}
}
for _, srv := range g.Users {
if strings.HasPrefix(srv.Name, "ENV$") {
srv.Name = os.Getenv(strings.TrimPrefix(srv.Name, "ENV$"))
}
if strings.HasPrefix(srv.Password, "ENV$") {
srv.Password = os.Getenv(strings.TrimPrefix(srv.Password, "ENV$"))
}
}
}
}
spew.Println(g)
return &g, nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment