aboutsummaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 16:04:19 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 16:04:19 +0100
commitf4368074a7cc07ad305ae9fb9b08d6b8dd3025eb (patch)
tree4fb677a7e41748d5db2ae57192f03d9443b909e5 /config.go
parent94a11e552b50a389a4e3a6b5fe7bdea4ce7097a4 (diff)
feat(context): create custom with config data in
Diffstat (limited to 'config.go')
-rw-r--r--config.go64
1 files changed, 0 insertions, 64 deletions
diff --git a/config.go b/config.go
deleted file mode 100644
index 725074c..0000000
--- a/config.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package main
-
-import (
- "fmt"
- "os"
-
- "github.com/pelletier/go-toml/v2"
- "gorm.io/driver/postgres"
- "gorm.io/gorm"
-)
-
-type Config struct {
- Debug bool `toml:"debug"`
- Author string `toml:"author"`
- Database *PostgresConfig `toml:"database"`
-}
-
-type PostgresConfig struct {
- Host string `toml:"host"`
- User string `toml:"user"`
- Password string `toml:"password"`
- DBName string `toml:"db_name"`
- Port int `toml:"port"`
-}
-
-func (p *PostgresConfig) SetDefaultValues() {
- p.Host = "localhost"
- p.User = ""
- p.Password = ""
- p.DBName = ""
- p.Port = 5432
-}
-
-func (p *PostgresConfig) Connect() (*gorm.DB, error) {
- db, err := gorm.Open(postgres.Open(p.generateDsn()), &gorm.Config{})
- if err != nil {
- return nil, err
- }
- return db, nil
-}
-
-// 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",
- p.Host, p.User, p.Password, p.DBName, p.Port,
- )
-}
-
-func (c *Config) SetDefaultValues() {
- c.Debug = false
- c.Author = "anhgelus"
- c.Database = &PostgresConfig{}
- c.Database.SetDefaultValues()
-}
-
-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)
-}