Skip to content

Commit

Permalink
✨ add sslmode for postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Jan 19, 2022
1 parent 54272db commit 68f1ccf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions bootstrap/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ func InitModel() {
}
case "postgres":
{
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
databaseConfig.Host, databaseConfig.User, databaseConfig.Password, databaseConfig.Name, databaseConfig.Port)
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s TimeZone=Asia/Shanghai",
databaseConfig.Host, databaseConfig.User, databaseConfig.Password, databaseConfig.Name, databaseConfig.Port, databaseConfig.SslMode)
db, err := gorm.Open(postgres.Open(dsn), gormConfig)
if err != nil {
log.Errorf("failed to connect database:%s", err.Error())
}
conf.DB = db

}
default:
log.Fatalf("not supported database type: %s", databaseConfig.Type)
Expand Down
2 changes: 2 additions & 0 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Database struct {
Name string `json:"name"`
TablePrefix string `json:"table_prefix"`
DBFile string `json:"db_file"`
SslMode string `json:"ssl_mode"`
}

type Scheme struct {
Expand Down Expand Up @@ -41,6 +42,7 @@ func DefaultConfig() *Config {
Port: 0,
TablePrefix: "x_",
DBFile: "data/data.db",
SslMode: "disable",
},
Cache: CacheConfig{
Expiration: 60,
Expand Down

0 comments on commit 68f1ccf

Please sign in to comment.