Fix omitempty

This commit is contained in:
Ymnuk 2023-11-16 13:55:36 +03:00
parent 2243da0360
commit b6a8452503
6 changed files with 14 additions and 14 deletions

View File

@ -8,5 +8,5 @@ type BaseInt struct {
ID uint64 `gorm:"primaryKey" json:"id,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// DeletedAt *time.Time `sql:"index" json:"deletedAt"`
// DeletedAt *time.Time `sql:"index" json:"deletedAt,omitempty"`
}

View File

@ -13,7 +13,7 @@ type Base struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id,omitempty"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// DeletedAt *time.Time `sql:"index" json:"deletedAt"`
// DeletedAt *time.Time `sql:"index" json:"deletedAt,omitempty"`
}
// BeforeCreate will set a UUID rather than numeric ID.

View File

@ -17,7 +17,7 @@ type {{ fieldNamePrepare .Name }} struct {
{{ end }}
{{ range $index, $field := .Fields }}
{{ fieldName $field }} {{ fieldType $field }} `gorm:"column:{{ fieldNameLowerPrepare $field.Name }};comment:{{ $field.Description }}" json:"{{ fieldJsonNameStr $field.Name }},omitmnpty"`
{{ fieldName $field }} {{ fieldType $field }} `gorm:"column:{{ fieldNameLowerPrepare $field.Name }};comment:{{ $field.Description }}" json:"{{ fieldJsonNameStr $field.Name }},omitempty"`
{{ end }}
{{ range $index, $field := .Children }}

View File

@ -3,8 +3,8 @@ package model
// Role Роли пользователей
type Role struct {
Base
Name string `gorm:"type:varchar(30);comment:Название роли" json:"name"`
Display *string `gorm:"type:text;comment:Отображаемое название роли" json:"display"`
Description *string `gorm:"type:text;comment:Описание роли" json:"description"`
Name string `gorm:"type:varchar(30);comment:Название роли" json:"name,omitempty"`
Display *string `gorm:"type:text;comment:Отображаемое название роли" json:"display,omitempty"`
Description *string `gorm:"type:text;comment:Описание роли" json:"description,omitempty"`
UserRole []UserRole
}

View File

@ -5,8 +5,8 @@ import uuid "github.com/satori/go.uuid"
// UserRole Связь пользователя и роли
type UserRole struct {
Base
UserID uuid.UUID `gorm:"column:id_user"`
UserID uuid.UUID `gorm:"column:id_user,omitempty"`
User User
RoleID uuid.UUID `gorm:"column:id_role"`
RoleID uuid.UUID `gorm:"column:id_role,omitempty"`
Role Role
}

View File

@ -15,18 +15,18 @@ import (
type User struct {
Base
Login string `json:"login"`
Surname string `gorm:"column:surname;type:varchar;size:100;comment:Фамилия" json:"surname"`
Name string `gorm:"column:name;type:varchar;size:100;comment:Имя" json:"name"`
Farname *string `gorm:"column:farname;type:varchar;size:100;comment:Отчество" json:"farname"`
Email *string `gorm:"column:email;type:varchar;size:200;comment:Адрес электронной почты" json:"email"`
Password *string `gorm:"-" json:"password"`
Surname string `gorm:"column:surname;type:varchar;size:100;comment:Фамилия" json:"surname,omitempty"`
Name string `gorm:"column:name;type:varchar;size:100;comment:Имя" json:"name,omitempty"`
Farname *string `gorm:"column:farname;type:varchar;size:100;comment:Отчество" json:"farname,omitempty"`
Email *string `gorm:"column:email;type:varchar;size:200;comment:Адрес электронной почты" json:"email,omitempty"`
Password *string `gorm:"-" json:"password,omitempty"`
UserRole []UserRole
Sha256pwd string `json:"-"`
Sha256salt string `json:"-"`
Sha512pwd string `json:"-"`
Sha512salt string `json:"-"`
Ldap bool `gorm:"comment:Проводить ли аутентификацию через LDAP?" json:"ldap,omitempty"`
Attempt int `gorm:"comment:Количество неудачных попыток" json:"attempt"`
Attempt int `gorm:"comment:Количество неудачных попыток" json:"attempt,omitempty"`
Roles *[]Role `gorm:"-" json:"roles,omitempty"`
}