model

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package model provides ...

Index

Constants

View Source
const (
	MenuPlatformAll     = "all"
	MenuPlatformWeb     = "web"
	MenuPlatformMobile  = "mobile"
	MenuPlatformDesktop = "desktop"
)

Variables

View Source
var (
	// Records is the table records must be pr-eexists before any database curd,
	// its register by register function.
	// The underlying type of map value must be model pointer to structure, eg: *model.User
	//
	// Records is the table records that should created automatically when app bootstraping.
	Records []*Record = make([]*Record, 0)

	// Tables is the database table that should created automatically when app bootstraping.
	Tables []types.Model

	TablesWithDB []struct {
		Table  types.Model
		DBName string
	}

	// Routes map an API path to its allowed HTTP methods.
	// The key is the API endpoint path (e.g., "/user/:id")
	// and the value is a list of supported HTTP methods (e.g., GET, POST, DELETE).
	Routes map[string][]string = make(map[string][]string)
)
View Source
var (
	RootID      = "root"
	RootName    = "root"
	UnknownID   = "unknown"
	UnknownName = "未知"
	NoneID      = "none"
	NoneName    = "无"

	KeyName = "name"
	KeyID   = "id"
)
View Source
var ErrMobileLength = errors.New("mobile number length must be 11")
View Source
var MenuRoot = &Menu{ParentID: RootID, Base: Base{ID: RootID}}

Functions

func AreTypesEqual

func AreTypesEqual[M types.Model, REQ types.Request, RSP types.Response]() bool

AreTypesEqual checks if the types of M, REQ and RSP are equal If the M is a struct only has field model.Empty, always return false.

func GetTableName

func GetTableName[M types.Model]() string

func IsModelEmpty

func IsModelEmpty[T any]() bool

IsModelEmpty check the REQ is struct only has anonymous field model.Empty or has no fields, eg:

type Login struct {
	model.Empty
}

type Logout struct{
}

func Register

func Register[M types.Model](records ...M)

Register associates the model with database table and will created automatically. If records provided, they will be inserted when application bootstrapping.

Parameters:

  • records: Optional initial records to be seeded into the table. Can be single or multiple records.

Examples:

// Create table 'users' only
Register[*model.User]()

// Create table 'users' and insert one record
Register[*model.User](&model.User{ID: 1, Name: "admin"})

// Create table 'users' and insert a single user record
Register[*model.User](user)

// Create table 'users' and insert multiple records
Register[*model.User](users...)  // where users is []*model.User

NOTE:

  1. Always call this function in init().
  2. Ensure the model package is imported in main.go. The init() function will only executed if the file is imported directly or indirectly by main.go.

func RegisterRoutes deprecated

func RegisterRoutes[M types.Model](path string, verbs ...consts.HTTPVerb)

RegisterRoutes register one route path with multiple api verbs. call this function multiple to register multiple route path. If route path is same, using latest register route path.

Deprecated: use router.Register() instead. This function is a no-op.

func RegisterTo

func RegisterTo[M types.Model](dbname string, records ...M)

RegisterTo works identically to Register(), but registers the model on the specified database instance. more details see: Register().

Types

type Avatar

type Avatar struct {
	URL    string `json:"url,omitempty"`    // 用户头像
	Thumb  string `json:"thumb,omitempty"`  // 用户头像 72x72
	Middle string `json:"middle,omitempty"` // 用户头像 240x240
	Big    string `json:"big,omitempty"`    // 用户头像 640x640
}

func (*Avatar) Scan

func (a *Avatar) Scan(value any) error

func (Avatar) Value

func (a Avatar) Value() (driver.Value, error)

type BIOS

type BIOS struct {
	Vendor  string `json:"vendor,omitempty"`
	Version string `json:"version,omitempty"`
	Date    string `json:"date,omitempty"`
}

type Base

type Base struct {
	ID string `json:"id" gorm:"primaryKey" schema:"id" url:"-"` // Unique identifier for the record

	CreatedBy string         `json:"created_by,omitempty" gorm:"index" schema:"created_by" url:"-"` // User ID who created the record
	UpdatedBy string         `json:"updated_by,omitempty" gorm:"index" schema:"updated_by" url:"-"` // User ID who last updated the record
	CreatedAt *time.Time     `json:"created_at,omitempty" gorm:"index" schema:"-" url:"-"`          // Timestamp when the record was created
	UpdatedAt *time.Time     `json:"updated_at,omitempty" gorm:"index" schema:"-" url:"-"`          // Timestamp when the record was last updated
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index" schema:"-" url:"-"`                             // Timestamp when the record was deleted
	Remark    *string        `json:"remark,omitempty" gorm:"size:10240" schema:"-" url:"-"`         // Optional remark or note for the record (pointer type for PATCH support)
	Order     *uint          `json:"order,omitempty" schema:"-" url:"-"`                            // Optional ordering value for sorting records

	// Query parameter
	Page       uint    `json:"-" gorm:"-" schema:"page" url:"page,omitempty"`                 // Pagination: page number (e.g., page=2)
	Size       uint    `json:"-" gorm:"-" schema:"size" url:"size,omitempty"`                 // Pagination: page size (e.g., size=10)
	Expand     *string `json:"-" gorm:"-" schema:"_expand" url:"_expand,omitempty"`           // Query parameter: fields to expand (e.g., _expand=children,parent)
	Depth      *uint   `json:"-" gorm:"-" schema:"_depth" url:"_depth,omitempty"`             // Query parameter: expansion depth (e.g., _depth=3)
	Fuzzy      *bool   `json:"-" gorm:"-" schema:"_fuzzy" url:"_fuzzy,omitempty"`             // Query parameter: enable fuzzy search (e.g., _fuzzy=true)
	SortBy     string  `json:"-" gorm:"-" schema:"_sortby" url:"_sortby,omitempty"`           // Query parameter: field to sort by (e.g., _sortby=name)
	NoCache    bool    `json:"-" gorm:"-" schema:"_nocache" url:"_nocache,omitempty"`         // Query parameter: disable cache (e.g., _nocache=false)
	ColumnName string  `json:"-" gorm:"-" schema:"_column_name" url:"_column_name,omitempty"` // Query parameter: column name for time range filtering (e.g., _column_name=created_at)
	StartTime  string  `json:"-" gorm:"-" schema:"_start_time" url:"_start_time,omitempty"`   // Query parameter: start time for range filtering (e.g., _start_time=2024-04-29+23:59:59)
	EndTime    string  `json:"-" gorm:"-" schema:"_end_time" url:"_end_time,omitempty"`       // Query parameter: end time for range filtering (e.g., _end_time=2024-04-29+23:59:59)
	Or         *bool   `json:"-" gorm:"-" schema:"_or" url:"_or,omitempty"`                   // Query parameter: use OR logic for conditions (e.g., _or=true)
	Index      string  `json:"-" gorm:"-" schema:"_index" url:"_index,omitempty"`             // Query parameter: index name for search (e.g., _index=name)
	Select     string  `json:"-" gorm:"-" schema:"_select" url:"_select,omitempty"`           // Query parameter: specific fields to select (e.g., _select=field1,field2)
	Nototal    bool    `json:"-" gorm:"-" schema:"_nototal" url:"_nototal,omitempty"`         // Query parameter: skip total count calculation (e.g., _nototal=true)

	// cursor pagination
	CursorValue  *string `json:"-" gorm:"-" schema:"_cursor_value" url:"_cursor_value,omitempty"`   // Query parameter: cursor value for pagination (e.g., _cursor_value=0196a0b3-c9d1-713c-870e-adc76af9f857)
	CursorFields string  `json:"-" gorm:"-" schema:"_cursor_fields" url:"_cursor_fields,omitempty"` // Query parameter: fields used for cursor pagination (e.g., _cursor_fields=field1,field2)
	CursorNext   bool    `json:"-" gorm:"-" schema:"_cursor_next" url:"_cursor_next,omitempty"`     // Query parameter: direction for cursor pagination (e.g., _cursor_next=true)

}

Base implement types.Model interface. Each model must be expands the Base structure. You can implements your custom method to overwrite the defaults methods.

Usually, there are some gorm tags that may be of interest to you. gorm:"unique" gorm:"foreignKey:ParentID" gorm:"foreignKey:ParentID,references:ID"

func (*Base) ClearID

func (b *Base) ClearID()

func (*Base) CreateAfter

func (*Base) CreateAfter(*types.ModelContext) error

func (*Base) CreateBefore

func (*Base) CreateBefore(*types.ModelContext) error

func (*Base) DeleteAfter

func (*Base) DeleteAfter(*types.ModelContext) error

func (*Base) DeleteBefore

func (*Base) DeleteBefore(*types.ModelContext) error

func (*Base) Excludes

func (b *Base) Excludes() map[string][]any

func (*Base) Expands

func (b *Base) Expands() []string

func (*Base) GetAfter

func (*Base) GetAfter(*types.ModelContext) error

func (*Base) GetBefore

func (*Base) GetBefore(*types.ModelContext) error

func (*Base) GetCreatedAt

func (b *Base) GetCreatedAt() time.Time

func (*Base) GetCreatedBy

func (b *Base) GetCreatedBy() string

func (*Base) GetID

func (b *Base) GetID() string

func (*Base) GetTableName

func (b *Base) GetTableName() string

func (*Base) GetUpdatedAt

func (b *Base) GetUpdatedAt() time.Time

func (*Base) GetUpdatedBy

func (b *Base) GetUpdatedBy() string

func (*Base) ListAfter

func (*Base) ListAfter(*types.ModelContext) error

func (*Base) ListBefore

func (*Base) ListBefore(*types.ModelContext) error

func (*Base) MarshalLogObject

func (b *Base) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Base) SetCreatedAt

func (b *Base) SetCreatedAt(t time.Time)

func (*Base) SetCreatedBy

func (b *Base) SetCreatedBy(s string)

func (*Base) SetID

func (b *Base) SetID(id ...string)

func (*Base) SetUpdatedAt

func (b *Base) SetUpdatedAt(t time.Time)

func (*Base) SetUpdatedBy

func (b *Base) SetUpdatedBy(s string)

func (*Base) UpdateAfter

func (*Base) UpdateAfter(*types.ModelContext) error

func (*Base) UpdateBefore

func (*Base) UpdateBefore(*types.ModelContext) error

type Board

type Board struct {
	Name     string `json:"name,omitempty"`
	Vendor   string `json:"vendor,omitempty"`
	Version  string `json:"version,omitempty"`
	Serial   string `json:"serial,omitempty"`
	AssetTag string `json:"assettag,omitempty"`
}

type CPU

type CPU struct {
	Vendor  string `json:"vendor,omitempty"`
	Model   string `json:"model,omitempty"`
	Speed   uint   `json:"speed,omitempty"`   // CPU clock rate in MHz
	Cache   uint   `json:"cache,omitempty"`   // CPU cache size in KB
	Cpus    uint   `json:"cpus,omitempty"`    // number of physical CPUs
	Cores   uint   `json:"cores,omitempty"`   // number of physical CPU cores
	Threads uint   `json:"threads,omitempty"` // number of logical (HT) CPU cores
}

type Chassis

type Chassis struct {
	Type     uint   `json:"type,omitempty"`
	Vendor   string `json:"vendor,omitempty"`
	Version  string `json:"version,omitempty"`
	Serial   string `json:"serial,omitempty"`
	AssetTag string `json:"assettag,omitempty"`
}

type Empty

type Empty struct{}

Empty is a special model implementation that provides a no-op implementation of the types.Model interface. It serves as a marker type for structs that should be excluded from database operations and service hooks.

Key characteristics:

  • Structs with an anonymous model.Empty field are never migrated to the database
  • All interface methods return zero values or no-op implementations
  • IsModelEmpty() function returns true for structs containing only model.Empty
  • Service hooks are bypassed when AreTypesEqual() returns false for Empty types
  • Commonly used for request/response DTOs that don't require persistence

Usage example:

type LoginRequest struct {
    model.Empty
    Username string `json:"username"`
    Password string `json:"password"`
}

func (Empty) ClearID

func (Empty) ClearID()

func (Empty) CreateAfter

func (Empty) CreateAfter(*types.ModelContext) error

func (Empty) CreateBefore

func (Empty) CreateBefore(*types.ModelContext) error

func (Empty) DeleteAfter

func (Empty) DeleteAfter(*types.ModelContext) error

func (Empty) DeleteBefore

func (Empty) DeleteBefore(*types.ModelContext) error

func (Empty) Excludes

func (Empty) Excludes() map[string][]any

func (Empty) Expands

func (Empty) Expands() []string

func (Empty) GetAfter

func (Empty) GetAfter(*types.ModelContext) error

func (Empty) GetBefore

func (Empty) GetBefore(*types.ModelContext) error

func (Empty) GetCreatedAt

func (Empty) GetCreatedAt() time.Time

func (Empty) GetCreatedBy

func (Empty) GetCreatedBy() string

func (Empty) GetID

func (Empty) GetID() string

func (Empty) GetTableName

func (Empty) GetTableName() string

func (Empty) GetUpdatedAt

func (Empty) GetUpdatedAt() time.Time

func (Empty) GetUpdatedBy

func (Empty) GetUpdatedBy() string

func (Empty) ListAfter

func (Empty) ListAfter(*types.ModelContext) error

func (Empty) ListBefore

func (Empty) ListBefore(*types.ModelContext) error

func (Empty) MarshalLogObject

func (Empty) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (Empty) SetCreatedAt

func (Empty) SetCreatedAt(t time.Time)

func (Empty) SetCreatedBy

func (Empty) SetCreatedBy(s string)

func (Empty) SetID

func (Empty) SetID(id ...string)

func (Empty) SetUpdatedAt

func (Empty) SetUpdatedAt(t time.Time)

func (Empty) SetUpdatedBy

func (Empty) SetUpdatedBy(s string)

func (Empty) UpdateAfter

func (Empty) UpdateAfter(*types.ModelContext) error

func (Empty) UpdateBefore

func (Empty) UpdateBefore(*types.ModelContext) error

type Fixed

type Fixed string
const (
	FIXED_RIGHT Fixed = "right" //nolint:staticcheck
	FIXED_LEFT  Fixed = "left"  //nolint:staticcheck
)

type GormScanner

type GormScanner struct {
	Object any
}

func GormScannerWrapper

func GormScannerWrapper(object any) *GormScanner

GormScannerWrapper converts object to GormScanner that can be used in GORM. WARN: you must pass pointer to object.

func (*GormScanner) Scan

func (g *GormScanner) Scan(value any) (err error)

func (*GormScanner) Value

func (g *GormScanner) Value() (driver.Value, error)

type GormStrings

type GormStrings []string

func (*GormStrings) Scan

func (gs *GormStrings) Scan(value any) error

func (*GormStrings) UnmarshalJSON

func (gs *GormStrings) UnmarshalJSON(data []byte) error

func (GormStrings) Value

func (gs GormStrings) Value() (driver.Value, error)

type GormTime

type GormTime time.Time

func (GormTime) MarshalJSON

func (gt GormTime) MarshalJSON() ([]byte, error)

func (*GormTime) Scan

func (gt *GormTime) Scan(value any) error

func (*GormTime) UnmarshalJSON

func (gt *GormTime) UnmarshalJSON(b []byte) error

func (GormTime) Value

func (gt GormTime) Value() (driver.Value, error)

type Kernel

type Kernel struct {
	Release      string `json:"release,omitempty"`
	Version      string `json:"version,omitempty"`
	Architecture string `json:"architecture,omitempty"`
}

type Memory

type Memory struct {
	Type  string `json:"type,omitempty"`
	Speed uint   `json:"speed,omitempty"` // RAM data rate in MT/s
	Size  uint   `json:"size,omitempty"`  // RAM size in MB
}
type Menu struct {
	API     string `json:"api,omitempty" schema:"api"` // 后端路由, 如果为空则使用 "/api" + Path
	Path    string `json:"path" schema:"path"`         // path should not add `omitempty` tag, empty value means default router in react route6.x.
	Element string `json:"element,omitempty" schema:"element"`
	Label   string `json:"label,omitempty" schema:"label"`
	Icon    string `json:"icon,omitempty" schema:"icon"`

	Visiable *bool  `json:"visiable" schema:"visiable"`                                                                    // 默认路由
	Default  string `json:"default,omitempty" schema:"default"`                                                            // 自路由中的默认路由, 如果有 Children, Default 才可能存在
	Status   *uint  `json:"status" gorm:"type:smallint;default:1;comment:status(0: disabled, 1: enabled)" schema:"status"` // 该路由是否启用

	ParentID string  `json:"parent_id,omitempty" gorm:"size:191" schema:"parent_id"`
	Children []*Menu `json:"children,omitempty" gorm:"foreignKey:ParentId"`             // 子路由
	Parent   *Menu   `json:"parent,omitempty" gorm:"foreignKey:ParentId;references:ID"` // 父路由

	// the empty value of `Platform` means all.
	Platform MenuPlatform `json:"platform" schema:"platform"`

	DomainPattern string `json:"domain_pattern" schema:"domain_pattern"`

	Base
}

Menu: 菜单 TODO: 加一个 api 用来指定后端路由,如果为空则使用 Path.

func (m *Menu) CreateBefore(ctx *types.ModelContext) (err error)
func (m *Menu) Excludes() map[string][]any
func (m *Menu) Expands() []string
func (m *Menu) GetAfter(ctx *types.ModelContext) (err error)
func (m *Menu) ListAfter(ctx *types.ModelContext) (err error)

ListAfter 可能是只查询最顶层的 Menu,并不能拿到最顶层的 Menu

func (m *Menu) MarshalLogObject(enc zapcore.ObjectEncoder) error
func (m *Menu) UpdateBefore(ctx *types.ModelContext) error
type MenuPlatform string

type NetworkDevice

type NetworkDevice struct {
	Name       string `json:"name,omitempty"`
	Driver     string `json:"driver,omitempty"`
	MACAddress string `json:"macaddress,omitempty"`
	Port       string `json:"port,omitempty"`
	Speed      uint   `json:"speed,omitempty"` // device max supported speed in Mbps
}

type NetworkDevices

type NetworkDevices []NetworkDevice

func (*NetworkDevices) Scan

func (nd *NetworkDevices) Scan(value any) error

func (NetworkDevices) Value

func (nd NetworkDevices) Value() (driver.Value, error)

type Node

type Node struct {
	Hostname   string `json:"hostname,omitempty"`
	MachineID  string `json:"machineid,omitempty"`
	Hypervisor string `json:"hypervisor,omitempty"`
	Timezone   string `json:"timezone,omitempty"`
}

type OS

type OS struct {
	Name         string `json:"name,omitempty"`
	Vendor       string `json:"vendor,omitempty"`
	Version      string `json:"version,omitempty"`
	Release      string `json:"release,omitempty"`
	Architecture string `json:"architecture,omitempty"`
}

type Product

type Product struct {
	Name    string `json:"name,omitempty"`
	Vendor  string `json:"vendor,omitempty"`
	Version string `json:"version,omitempty"`
	Serial  string `json:"serial,omitempty"`
	UUID    string `json:"uuid,omitempty"`
	SKU     string `json:"sku,omitempty"`
}

type Record

type Record struct {
	Table   types.Model
	Rows    any
	Expands []string
	DBName  string
}

Record is table record

type Session

type Session struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	UserID       string `json:"user_id"`
	Username     string `json:"username"`
	SessionID    string `json:"session_id"`

	// TODO: 统一起来,使用 model.UserAgent
	Platform       string `json:"platform"`
	OS             string `json:"os"`
	EngineName     string `json:"engine_name"`
	EngineVersion  string `json:"engine_version"`
	BrowserName    string `json:"browser_name"`
	BrowserVersion string `json:"browser_version"`

	Base
}

func (*Session) CreateBefore

func (s *Session) CreateBefore(*types.ModelContext) error

func (*Session) DeleteBefore

func (s *Session) DeleteBefore(*types.ModelContext) error

func (*Session) UpdateBefore

func (s *Session) UpdateBefore(*types.ModelContext) error

type StorageDevice

type StorageDevice struct {
	Name   string `json:"name,omitempty"`
	Driver string `json:"driver,omitempty"`
	Vendor string `json:"vendor,omitempty"`
	Model  string `json:"model,omitempty"`
	Serial string `json:"serial,omitempty"`
	Size   uint   `json:"size,omitempty"` // device size in GB
}

type StorageDevices

type StorageDevices []StorageDevice

func (*StorageDevices) Scan

func (sd *StorageDevices) Scan(value any) error

func (StorageDevices) Value

func (sd StorageDevices) Value() (driver.Value, error)

type SysInfo

type SysInfo struct {
	Node    Node    `json:"node" gorm:"embedded;embeddedPrefix:node_"`
	OS      OS      `json:"os" gorm:"embedded;embeddedPrefix:os_"`
	Kernel  Kernel  `json:"kernel" gorm:"embedded;embeddedPrefix:kernel_"`
	Product Product `json:"product" gorm:"embedded;embeddedPrefix:product_"`
	Board   Board   `json:"board" gorm:"embedded;embeddedPrefix:board_"`
	Chassis Chassis `json:"chassis" gorm:"embedded;embeddedPrefix:chassis_"`
	BIOS    BIOS    `json:"bios" gorm:"embedded;embeddedPrefix:bios_"`
	CPU     CPU     `json:"cpu" gorm:"embedded;embeddedPrefix:cpu_"`
	Memory  Memory  `json:"memory" gorm:"embedded;embeddedPrefix:memory_"`

	Storages StorageDevices `json:"storages,omitempty"`
	Networks NetworkDevices `json:"networks,omitempty"`

	Base
}

func (*SysInfo) CreateBefore

func (si *SysInfo) CreateBefore() error

func (*SysInfo) UpdateBefore

func (si *SysInfo) UpdateBefore() error

type TableColumn

type TableColumn struct {
	UserID    string `json:"user_id,omitempty" schema:"user_id"`       // 属于哪一个用户的
	TableName string `json:"table_name,omitempty" schema:"table_name"` // 属于哪一张表的
	Name      string `json:"name,omitempty" schema:"name"`             // 列名
	Key       string `json:"key,omitempty" schema:"key"`               // 列名对应的id

	Width    *uint   `json:"width,omitempty"`    // 列宽度
	Sequence *uint   `json:"sequence,omitempty"` // 列顺序
	Visiable *bool   `json:"visiable,omitempty"` // 是否显示
	Fixed    *string `json:"fixed,omitempty"`    // 固定在哪里 left,right, 必须加上 omitempty

	Base
}

TableColumn 表格的列

func (*TableColumn) CreateBefore

func (t *TableColumn) CreateBefore(*types.ModelContext) error

func (*TableColumn) MarshalLogObject

func (t *TableColumn) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*TableColumn) UpdateBefore

func (t *TableColumn) UpdateBefore(*types.ModelContext) error

type User

type User struct {
	Name        string `json:"name,omitempty"`
	EnName      string `json:"en_name,omitempty"`
	Password    string `json:"password,omitempty"`
	RePassword  string `json:"re_password,omitempty" gorm:"-"`
	NewPassword string `json:"new_password,omitempty" gorm:"-"`
	Nickname    string `json:"nickname,omitempty"`

	Email          string `json:"email,omitempty"`
	EmailVerified  bool   `json:"email_verified,omitempty"`
	Mobile         string `json:"mobile,omitempty"`
	MobileVerified bool   `json:"mobile_verified,omitempty"`

	Status uint `json:"status,omitempty" gorm:"type:smallint;default:1;comment:status(0: disabled, 1: enabled)"`

	RoleID       string `json:"role_id,omitempty"`
	DepartmentID string `json:"department_id,omitempty"`

	LastLoginIP string `json:"last_login_ip,omitempty"`
	LockExpire  int64  `json:"lock_expire,omitempty"`
	LoginCount  int    `json:"login_count,omitempty"`
	NumWrong    int    `json:"num_wrong,omitempty" gorm:"comment:the number of input password wrong"`

	Avatar *Avatar `json:"avatar,omitempty"`

	LastLoginAt          *GormTime `json:"last_login,omitempty"`
	TokenExpiration      *GormTime `json:"token_expiration,omitempty"`
	LastPasswordChangeAt *GormTime `json:"last_password_change_at,omitempty" gorm:"-"`

	Token        string `json:"token,omitempty" gorm:"-"`
	AccessToken  string `json:"access_token,omitempty" gorm:"-"`
	RefreshToken string `json:"refresh_token,omitempty" gorm:"-"`
	SessionID    string `json:"session_id,omitempty" gorm:"-"`

	Base
}

func (*User) MarshalLogObject

func (u *User) MarshalLogObject(enc zapcore.ObjectEncoder) error

type UserAgent

type UserAgent struct {
	Source   string `json:"source" schema:"source"`
	Platform string `json:"platform" schema:"platform"`
	Engine   string `json:"engine" schema:"engine"`
	Browser  string `json:"browser" schema:"browser"`
}

type UserInfo

type UserInfo struct {
	AccessToken      string `json:"access_token,omitempty"`       // user_access_token,用于获取用户资源
	TokenType        string `json:"token_type,omitempty"`         // token 类型
	ExpiresIn        int    `json:"expires_in,omitempty"`         // `access_token`的有效期,单位: 秒
	Name             string `json:"name,omitempty"`               // 用户姓名
	EnName           string `json:"en_name,omitempty"`            // 用户英文名称
	AvatarURL        string `json:"avatar_url,omitempty"`         // 用户头像
	AvatarThumb      string `json:"avatar_thumb,omitempty"`       // 用户头像 72x72
	AvatarMiddle     string `json:"avatar_middle,omitempty"`      // 用户头像 240x240
	AvatarBig        string `json:"avatar_big,omitempty"`         // 用户头像 640x640
	OpenID           string `json:"open_id,omitempty"`            // 用户在应用内的唯一标识
	UnionID          string `json:"union_id,omitempty"`           // 用户统一ID
	Email            string `json:"email,omitempty"`              // 用户邮箱
	EnterpriseEmail  string `json:"enterprise_email,omitempty"`   // 企业邮箱,请先确保已在管理后台启用飞书邮箱服务
	UserID           string `json:"user_id,omitempty"`            // 用户 user_id
	Mobile           string `json:"mobile,omitempty"`             // 用户手机号
	TenantKey        string `json:"tenant_key,omitempty"`         // 当前企业标识
	RefreshExpiresIn int    `json:"refresh_expires_in,omitempty"` // `refresh_token` 的有效期,单位: 秒
	RefreshToken     string `json:"refresh_token,omitempty"`      // 刷新用户 `access_token` 时使用的 token
	Sid              string `json:"sid,omitempty"`                // 用户当前登录态session的唯一标识,为空则不返回

	Base
}

func (*UserInfo) MarshalLogObject

func (u *UserInfo) MarshalLogObject(enc zapcore.ObjectEncoder) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL