From 1597c23f84346dfa44da9605286863b11006bdb5 Mon Sep 17 00:00:00 2001 From: Alexander Kavon Date: Tue, 28 Nov 2023 18:32:19 -0500 Subject: added migrations via tern, updated db package to connect to pgsql db, updated config to build db connection string, updated example .newsstand.toml config, new pgx dependency --- src/conf/conf.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'src/conf/conf.go') diff --git a/src/conf/conf.go b/src/conf/conf.go index 7a6dcbf..62ffb57 100644 --- a/src/conf/conf.go +++ b/src/conf/conf.go @@ -1,6 +1,7 @@ package conf import ( + "fmt" "log" "os" @@ -18,7 +19,11 @@ type ( Db struct { Adapter string `toml:"adapter"` User string `toml:"user"` - Password string `toml:"pass"` + Secret string `toml:"secret"` + Hostname string `toml:"hostname"` + Port string `toml:"port"` + DbName string `toml:"dbname"` + Url string } Server struct { @@ -43,7 +48,9 @@ func NewConf() *Conf { c := Conf{ cwd, filepath, - Db{}, + Db{ + Hostname: "localhost", + }, Server{ UiPath: cwd + "/ui", }, @@ -52,11 +59,24 @@ func NewConf() *Conf { if err != nil { log.Fatalln(err) } + c.setDbUrl() log.Printf("Config loaded: %s", c) return &c } +func (c *Conf) setDbUrl() { + c.Db.Url = fmt.Sprintf( + "%s://%s:%s@%s:%s/%s", + c.Db.Adapter, + c.Db.User, + c.Db.Secret, + c.Db.Hostname, + c.Db.Port, + c.Db.DbName, + ) +} + func (c *Conf) GetCwd() string { return c.cwd } -- cgit v1.2.3