初步搭建

This commit is contained in:
des
2026-01-13 00:08:49 +08:00
parent d7854bbf1d
commit 0c68d57180
7 changed files with 114 additions and 14 deletions

View File

@@ -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("程序结束")
}