初步搭建
This commit is contained in:
20
srv/main.go
20
srv/main.go
@@ -10,28 +10,34 @@ import (
|
||||
)
|
||||
|
||||
type User struct {
|
||||
id int8
|
||||
createTime time.Time
|
||||
lastUpdateTime time.Time
|
||||
name string
|
||||
account string
|
||||
passwd string
|
||||
Id int8
|
||||
CreateTime time.Time
|
||||
LastUpdateTime time.Time
|
||||
Name string
|
||||
Account string
|
||||
Passwd string
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("程序启动!")
|
||||
dsn := "host=localhost " +
|
||||
"user=gatekeeper " +
|
||||
"dbname=crimson " +
|
||||
"sslmode=disable " +
|
||||
"port=5432 " +
|
||||
"password=crimson "
|
||||
"password=crimson " +
|
||||
"connect_timeout=20 "
|
||||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic("无法连接数据库")
|
||||
}
|
||||
fmt.Println("数据库连线完成")
|
||||
ctx := context.Background()
|
||||
|
||||
usr, err := gorm.G[User](db).First(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(usr)
|
||||
fmt.Println("程序结束")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user