Files
Crimson-Gatekeeper/srv/main.go

44 lines
702 B
Go
Raw Normal View History

2026-01-11 10:11:09 +08:00
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 (User) TableName() string {
return "user"
}
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()
user, err := gorm.G[User](db).First(ctx)
fmt.Println(user)
fmt.Println("程序结束")
return
}