model

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package model provides ...

Index

Constants

This section is empty.

Variables

View Source
var (

	// 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)

	// TableChan is a buffered channel for asynchronous table registration.
	// It receives table models from Register() function for processing by InitDatabase.
	// The channel supports concurrent registration and real-time processing during initialization.
	TableChan = make(chan types.Model, 10240)

	// TableDBChan is a buffered channel for asynchronous table registration with custom database targeting.
	// It receives TableDB structs from RegisterTo() function for processing by InitDatabase.
	// The channel supports concurrent registration and real-time processing during initialization.
	TableDBChan = make(chan *TableDB, 1024)

	// RecordChan is a buffered channel for asynchronous record insertion.
	// It receives Record structs from Register() and RegisterTo() functions for processing by InitDatabase.
	// The channel supports concurrent registration and ensures records are inserted after table creation.
	//
	// Records are table records that must pre-exist before any database CRUD operations.
	// They are registered by Register() or RegisterTo() functions and processed asynchronously.
	RecordChan = make(chan *Record, 1024)
)
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")

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 M "Empty" or "Any", return false directly.

NOTE: "Empty" or "Any" will cause always use custom controller operations.

func GetTableName

func GetTableName[M types.Model]() string

func IsEmpty added in v0.10.0

func IsEmpty[T any]() bool

IsEmpty check the T is a valid struct that has at least one valid field. What is a valid field? 1. the field is not a `Empty` or pointer to `Empty`. 2. the field is not a `Any` or pointer to `Any`.

For example, those bellow struct will returns true:

type Login struct {
	model.Empty
}

type Login struct {
	model.Empty
	model.Any
}

type Login struct {
	*model.Empty
	model.Any
}

type Logout struct{
}

func IsValid added in v0.10.0

func IsValid[T any]() bool

IsValid check whether the T is valid model.

If T is not pointer to struct, return false. If T has no fields, return false. If T fields contains `Empty` or `Any`, return false, otherwise return true.

func Register

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

Register associates the model with database table and will be created automatically. If records provided, they will be inserted when application bootstrapping. This function supports asynchronous registration and can be called at any stage - before, during, or after InitDatabase execution.

Key features:

  • Thread-safe concurrent registration using mutex protection
  • Asynchronous processing via goroutines and channels
  • Automatic ID generation for records without IDs
  • Real-time integration with InitDatabase process

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. Can be called in init() or at any time during application lifecycle.
  2. Ensure the model package is imported in main.go.
  3. The function is thread-safe and supports concurrent registration.

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. This function supports asynchronous registration and can be called at any stage - before, during, or after InitDatabase execution.

Key features:

  • Thread-safe concurrent registration using mutex protection
  • Asynchronous processing via goroutines and channels
  • Automatic ID generation for records without IDs
  • Real-time integration with InitDatabase process
  • Custom database instance targeting

Parameters:

  • dbname: The name of the target database instance (case-insensitive)
  • records: Optional initial records to be seeded into the table

For more details and examples, see: Register().

Types

type Any added in v0.9.7

type Any struct{}

Any is a special placeholder model type used for database transactions when you don't need to specify a concrete model type.

Usage example:

_ = database.Database[*model.Any](ctx.DatabaseContext()).TransactionFunc(func(tx any) error {
    // Perform database operations within transaction
    files := make([]*namespace.File, 0)
    if err = database.Database[*namespace.File](ctx.DatabaseContext()).
        WithTx(tx).
        WithQuery(&namespace.File{Format: namespace.FileFormat("kv")}).
        List(&files); err != nil {
        return err
    }
    for _, f := range files {
        f.Format = namespace.FileFomatShell
    }
    return database.Database[*namespace.File](ctx.DatabaseContext()).
        WithSelect("format").
        WithTx(tx).
        Update(files...)
})

Note:

  • Any does not correspond to any database table
  • It's only used as a type parameter for generic database operations
  • Unlike model.Empty, model.Any is specifically for transaction placeholders

func (Any) ClearID added in v0.9.7

func (Any) ClearID()

func (Any) CreateAfter added in v0.9.7

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

func (Any) CreateBefore added in v0.9.7

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

func (Any) DeleteAfter added in v0.9.7

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

func (Any) DeleteBefore added in v0.9.7

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

func (Any) Excludes added in v0.9.7

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

func (Any) Expands added in v0.9.7

func (Any) Expands() []string

func (Any) GetAfter added in v0.9.7

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

func (Any) GetBefore added in v0.9.7

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

func (Any) GetCreatedAt added in v0.9.7

func (Any) GetCreatedAt() time.Time

func (Any) GetCreatedBy added in v0.9.7

func (Any) GetCreatedBy() string

func (Any) GetID added in v0.9.7

func (Any) GetID() string

func (Any) GetTableName added in v0.9.7

func (Any) GetTableName() string

func (Any) GetUpdatedAt added in v0.9.7

func (Any) GetUpdatedAt() time.Time

func (Any) GetUpdatedBy added in v0.9.7

func (Any) GetUpdatedBy() string

func (Any) ListAfter added in v0.9.7

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

func (Any) ListBefore added in v0.9.7

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

func (Any) MarshalLogObject added in v0.9.7

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

func (Any) Purge added in v0.9.7

func (Any) Purge() bool

func (Any) SetCreatedAt added in v0.9.7

func (Any) SetCreatedAt(t time.Time)

func (Any) SetCreatedBy added in v0.9.7

func (Any) SetCreatedBy(s string)

func (Any) SetID added in v0.9.7

func (Any) SetID(id ...string)

func (Any) SetUpdatedAt added in v0.9.7

func (Any) SetUpdatedAt(t time.Time)

func (Any) SetUpdatedBy added in v0.9.7

func (Any) SetUpdatedBy(s string)

func (Any) UpdateAfter added in v0.9.7

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

func (Any) UpdateBefore added in v0.9.7

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

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) Purge added in v0.9.6

func (b *Base) Purge() bool

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) Purge added in v0.9.6

func (Empty) Purge() bool

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 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 TableDB added in v0.10.0

type TableDB struct {
	Table  types.Model // The table model to be registered
	DBName string      // The target database name (case-insensitive)
}

TableDB represents a table model with its target database name for custom database registration. It is used by RegisterTo() function to associate a table with a specific database instance. The struct is sent through TableDBChan for asynchronous processing by InitDatabase.

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

Jump to

Keyboard shortcuts

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