62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package configs
|
|
|
|
import "fmt"
|
|
|
|
type Postgres struct {
|
|
maxIdleConnectionTime string
|
|
maxConnectionLifetime string
|
|
maxOpenConnections int
|
|
maxIdleConnections int
|
|
host string
|
|
name string
|
|
port int
|
|
userName string
|
|
password string
|
|
sSLMode string
|
|
}
|
|
|
|
func getPostgresConfig() Postgres {
|
|
return Postgres{
|
|
maxConnectionLifetime: getString("db.connection.max.lifetime", true),
|
|
maxIdleConnectionTime: getString("db.connection.max.idle.time", true),
|
|
maxIdleConnections: getInt("db.connections.max.idle", true),
|
|
maxOpenConnections: getInt("db.connections.max.open", true),
|
|
userName: getString("db.username", true),
|
|
password: getString("db.password", true),
|
|
name: getString("db.name", true),
|
|
host: getString("db.host", true),
|
|
port: getInt("db.port", true),
|
|
sSLMode: getString("db.ssl.mode", true),
|
|
}
|
|
}
|
|
|
|
func (p Postgres) GetPostgresUrl() string {
|
|
return fmt.Sprintf(
|
|
"postgres://%s:%s@%s:%d/%s?sslmode=%s",
|
|
p.userName, p.password, p.host, p.port, p.name, p.sSLMode,
|
|
)
|
|
}
|
|
|
|
func (p Postgres) GetPostgresDsn() string {
|
|
return fmt.Sprintf(
|
|
"host=%s port=%d user=%s password=%s dbname=%s sslmode=%s",
|
|
p.host, p.port, p.userName, p.password, p.name, p.sSLMode,
|
|
)
|
|
}
|
|
|
|
func (p Postgres) GetMaxIdleConnectionTimeout() string {
|
|
return p.maxIdleConnectionTime
|
|
}
|
|
|
|
func (p Postgres) GetMaxConnectionLifetime() string {
|
|
return p.maxConnectionLifetime
|
|
}
|
|
|
|
func (p Postgres) GetMaxIdleConnections() int {
|
|
return p.maxIdleConnections
|
|
}
|
|
|
|
func (p Postgres) GetMaxOpenConnections() int {
|
|
return p.maxOpenConnections
|
|
}
|