aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go34
1 files changed, 10 insertions, 24 deletions
diff --git a/config.go b/config.go
index ff0472e..725074c 100644
--- a/config.go
+++ b/config.go
@@ -2,8 +2,8 @@ package main
import (
"fmt"
+ "os"
- "github.com/anhgelus/gokord"
"github.com/pelletier/go-toml/v2"
"gorm.io/driver/postgres"
"gorm.io/gorm"
@@ -41,23 +41,12 @@ func (p *PostgresConfig) Connect() (*gorm.DB, error) {
// generateDsn for the connection to postgres using the given config.SQLCredentials
func (p *PostgresConfig) generateDsn() string {
- return fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Europe/Paris",
+ return fmt.Sprintf(
+ "host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Europe/Paris",
p.Host, p.User, p.Password, p.DBName, p.Port,
)
}
-func (c *Config) IsDebug() bool {
- return c.Debug
-}
-
-func (c *Config) GetAuthor() string {
- return c.Author
-}
-
-func (c *Config) GetRedisCredentials() *gokord.RedisCredentials {
- return nil
-}
-
func (c *Config) SetDefaultValues() {
c.Debug = false
c.Author = "anhgelus"
@@ -65,14 +54,11 @@ func (c *Config) SetDefaultValues() {
c.Database.SetDefaultValues()
}
-func (c *Config) GetSQLCredentials() gokord.SQLCredentials {
- return c.Database
-}
-
-func (c *Config) Marshal() ([]byte, error) {
- return toml.Marshal(c)
-}
-
-func (c *Config) Unmarshal(bytes []byte) error {
- return toml.Unmarshal(bytes, c)
+func getConfig(path string) (*Config, error) {
+ b, err := os.ReadFile(path)
+ if err != nil {
+ return nil, err
+ }
+ var cfg Config
+ return &cfg, toml.Unmarshal(b, &cfg)
}