顺便说一句,使用金珠的GORM软件包,我目前有以下 struct :

type User struct {
    gorm.Model

    // The Users username
    Username string `gorm:"size:255;unique;not null"`

    // The Users email address
    Email string `gorm:"size:255;unique;not null"`

    // The Users hashed password
    Password string `gorm:"size:255;not null"`

    // The Users password confirmation (only for forms)
    PasswordC string `gorm:"-"`

    // The Users FULL NAME (e.g. Burt Reynolds)
    Fullname string `gorm:"size:255; not null"`

    // The Users Karma level
    Karma int

    // Is the user banned?
    Banned bool
}

但是我也使用了Gorilla的Schema包,所以任何表单值都会填充到 struct 中,但是我不希望将PasswordC保存到数据库中,因为它将是纯文本,因为普通的Password字段会被bcrypt,所以关于如何使GORM不保存PasswordC字段的任何信息.

推荐答案

docsgorm:"-",但code表示sql:"-"是正确的语法.

我的测试证实了这一点.

Go相关问答推荐

golang父进程的副本无法进行https/tls调用并获得tls:未能验证证书""

如何模拟嵌入. FS?

Hugo错误:没有为此项目配置现有内容目录

go mod tidy会自动升级go.mod中的go版本吗?

`docker system df` 与 `/system/df` (docker api 端点)

我怎样才能改进这个嵌套逻辑以使其正常工作并提高性能

我可以扫描表中每个项目的最高范围键值吗?

如何将 goose 迁移与 pgx 一起使用?

启动套接字服务器会干扰 gRPC/http 客户端服务器通信 Golang

如何在 fyne-io/fyne 中设置文本的字母间距?

Go struct 匿名字段是公开的还是私有的?

在密钥不存在时处理 PATCH 部分更新

Golang crypto/rand 线程安全吗?

如何将整数哈希细分为范围

没有任务角色的 AWS CDK ECS 任务定义

使用自定义处理程序 nats golang 保留订阅方法

如果 transaction.Commit 对带有 postgres 连接的 SQL 失败,您是否需要调用 transaction.RollBack

为什么在单独的 go routine 中需要 wg.Wait() 和 close() ?

Go 中 SDL Surface 的 OpenGL 纹理

如何在眼镜蛇(golang)中将标志作为参数传递?