Files
Crimson-Gatekeeper/srv/main.go
2026-01-13 00:08:49 +08:00

44 lines
769 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() {
fmt.Println("程序启动!")
dsn := "host=localhost " +
"user=gatekeeper " +
"dbname=crimson " +
"sslmode=disable " +
"port=5432 " +
"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("程序结束")
}