2025-09-05 18:35:46 +08:00
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
type postgresConfig struct {
|
|
|
|
|
Host string `json:"host" yaml:"host"`
|
|
|
|
|
Port int `json:"port" yaml:"port"`
|
|
|
|
|
User string `json:"user" yaml:"user"`
|
|
|
|
|
Password string `json:"password" yaml:"password"`
|
|
|
|
|
DBName string `json:"dbname" yaml:"dbname"`
|
|
|
|
|
SSLMode string `json:"sslmode" yaml:"sslmode"`
|
|
|
|
|
TimeZone string `json:"timezone" yaml:"timezone"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewPostgresConfig() *postgresConfig {
|
|
|
|
|
return new(postgresConfig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetHost() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.Host
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetHost(host string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.Host = host
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetPort() int {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.Port
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetPort(port int) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.Port = port
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetUser() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.User
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetUser(user string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.User = user
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetPassword() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.Password
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetPassword(password string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.Password = password
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetDBName() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.DBName
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetDBName(dbName string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.DBName = dbName
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetSSLMode() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.SSLMode
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetSSLMode(sslMode string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.SSLMode = sslMode
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (conf *postgresConfig) GetTimeZone() string {
|
|
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
2025-09-19 16:17:46 +08:00
|
|
|
|
2025-09-05 18:35:46 +08:00
|
|
|
return conf.TimeZone
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-19 16:17:46 +08:00
|
|
|
func (conf *postgresConfig) SetTimeZone(timeZone string) *postgresConfig {
|
2025-09-05 18:35:46 +08:00
|
|
|
if conf == nil {
|
|
|
|
|
panic("postgres config is nil")
|
|
|
|
|
}
|
|
|
|
|
conf.TimeZone = timeZone
|
2025-09-19 16:17:46 +08:00
|
|
|
|
|
|
|
|
return conf
|
2025-09-05 18:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func postgresConfigName() string {
|
|
|
|
|
return "postgres.json"
|
|
|
|
|
}
|