feat: gen model
This commit is contained in:
@@ -22,6 +22,7 @@ type Config struct {
|
||||
Username string
|
||||
Password string
|
||||
Database string
|
||||
Schema string
|
||||
Host string
|
||||
Port uint
|
||||
SslMode string
|
||||
@@ -56,6 +57,10 @@ func (m *Config) checkDefault() {
|
||||
if m.Port == 0 {
|
||||
m.Port = 5432
|
||||
}
|
||||
|
||||
if m.Schema == "" {
|
||||
m.Schema = "public"
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Config) EmptyDsn() string {
|
||||
@@ -68,6 +73,7 @@ func (m *Config) EmptyDsn() string {
|
||||
// DSN connection dsn
|
||||
func (m *Config) DSN() string {
|
||||
dsnTpl := "host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=%s"
|
||||
m.checkDefault()
|
||||
|
||||
return fmt.Sprintf(dsnTpl, m.Host, m.Username, m.Password, m.Database, m.Port, m.SslMode, m.TimeZone)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user