aboutsummaryrefslogtreecommitdiff
path: root/src/conf
diff options
context:
space:
mode:
authorAlexander Kavon <hawk@alexkavon.com>2023-11-28 18:32:19 -0500
committerAlexander Kavon <hawk@alexkavon.com>2023-11-28 18:32:19 -0500
commit1597c23f84346dfa44da9605286863b11006bdb5 (patch)
tree78a2abbefc1bbcc9a13691e09ac252b5400a5b00 /src/conf
parent629b0189b7bf20c748a1d37f8803ad0e3ffb8a49 (diff)
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
Diffstat (limited to 'src/conf')
-rw-r--r--src/conf/conf.go24
1 files changed, 22 insertions, 2 deletions
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
}