package config import ( "fmt" "time" ) type Database struct { Host string `mapstructure:"host"` Port string `mapstructure:"port"` DB string `mapstructure:"db"` Driver string `mapstructure:"driver"` Username string `mapstructure:"username"` Password string `mapstructure:"password"` SslMode string `mapstructure:"ssl-mode"` Debug bool `mapstructure:"debug"` MaxIdleConnectionsInSecond int `mapstructure:"max-idle-connections-in-second"` MaxOpenConnectionsInSecond int `mapstructure:"max-open-connections-in-second"` ConnectionMaxLifetimeInSecond int64 `mapstructure:"connection-max-life-time-in-second"` } func (c Database) DSN() string { return fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=%s TimeZone=Asia/Jakarta", c.Host, c.Port, c.DB, c.Username, c.Password, c.SslMode) } func (c Database) ConnectionMaxLifetime() time.Duration { return time.Duration(c.ConnectionMaxLifetimeInSecond) * time.Second }