From 42c25b54e169aeaf515522ba6103b1fe6db49be7 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 22 Jan 2026 13:06:52 +0100 Subject: refactor(config): replace old gokord config by custom one --- config.go | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'config.go') 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) } -- cgit v1.2.3