初步搭建
This commit is contained in:
21
srv/internal/common/database-client.go
Normal file
21
srv/internal/common/database-client.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"gorm.io/driver/postgres"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func GetDataBaseClient() *gorm.DB {
|
||||
dsn := "host=localhost " +
|
||||
"user=gatekeeper " +
|
||||
"dbname=crimson " +
|
||||
"sslmode=disable " +
|
||||
"port=5432 " +
|
||||
"password=crimson " +
|
||||
"connect_timeout=20 "
|
||||
client, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("无法连接数据库")
|
||||
}
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user