2023-10-08 15:59:42 +07:00
|
|
|
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 {
|
2024-09-06 15:12:50 +07:00
|
|
|
return fmt.Sprintf("host=%s port=%s dbname=%s user=%s password=%s sslmode=%s TimeZone=UTC", c.Host, c.Port, c.DB, c.Username, c.Password, c.SslMode)
|
2023-10-08 15:59:42 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c Database) ConnectionMaxLifetime() time.Duration {
|
|
|
|
|
return time.Duration(c.ConnectionMaxLifetimeInSecond) * time.Second
|
|
|
|
|
}
|