diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-22 13:06:52 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-01-22 13:06:52 +0100 |
| commit | 42c25b54e169aeaf515522ba6103b1fe6db49be7 (patch) | |
| tree | 7703222680d3b7cc9cebfcbbdd1ac7dc57475591 /config.go | |
| parent | df72cc3cb9daf5f284bb62caddf77cf1f1ea4154 (diff) | |
refactor(config): replace old gokord config by custom one
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 34 |
1 files changed, 10 insertions, 24 deletions
@@ -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) } |
