Files
Crimson-Gatekeeper/srv/main.go
2026-01-12 18:38:40 +08:00

38 lines
640 B
Go

package main
import (
"context"
"fmt"
"time"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
type User struct {
id int8
createTime time.Time
lastUpdateTime time.Time
name string
account string
passwd string
}
func main() {
dsn := "host=localhost " +
"user=gatekeeper " +
"dbname=crimson " +
"sslmode=disable " +
"port=5432 " +
"password=crimson "
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if err != nil {
panic("无法连接数据库")
}
ctx := context.Background()
usr, err := gorm.G[User](db).First(ctx)
fmt.Println(usr)
fmt.Println("程序结束")
}