如何在GORM中使用动态数据结构

We are developing a multi-tenant application with Go backend. We use Gorm as ORM library.

In some cases we have to assign some custom fields to certain users, so different structs for user X and user Y.

Is it possible to make structs dynamic?

static language golang doesn't support dynamic struct. Instead, I sugguest using a higher struct User containing all fields X and Y both have. Besides, Whether to design a bigger struct or different structs depends on your db model. If there is only one table in the database t_user, one model is good. If there are two or more tables like t_X ,t_Y, apparently you should design two or more models.