models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKindMismatch = errors.New("kind mismatch")

Functions

func EnsureRootUser

func EnsureRootUser(db *gorm.DB) error

EnsureRootUser ensures the super user "root" exists. EnsureRootUser 确保超级用户 root 存在。

func Migrate

func Migrate(db *gorm.DB) error

Migrate runs auto migrations. Migrate 执行数据库自动迁移。

Types

type Array

type Array struct {
	SiteID    string
	Site      Site      `gorm:"references:UUID"`
	UUID      string    `gorm:"primaryKey;column:uuid;size:36;uniqueIndex;not null" json:"uuid"`
	Name      string    `gorm:"column:name;size:150;uniqueIndex;not null" json:"name"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Array 子阵

func (Array) TableName

func (Array) TableName() string

TableName 用来显式指定表名(可选)

type AuditLog

type AuditLog struct {
	ID uint `gorm:"primaryKey" json:"id"`

	UserID   uint   `gorm:"index;not null" json:"user_id"`
	Username string `gorm:"index;size:64;not null" json:"username"`

	// Action: "login", "create_user", "change_password", ...
	// Action:动作,如 "login", "create_user", "change_password" 等。
	Action string `gorm:"size:64;index;not null" json:"action"`

	// Resource: "user", "token", "session", "audit"
	// Resource:资源类型,如 "user", "token", "session", "audit"
	Resource string `gorm:"size:64;index;not null" json:"resource"`

	Method string `gorm:"size:16;not null" json:"method"`
	Path   string `gorm:"size:256;not null" json:"path"`

	// Detail is extra JSON/text.
	// Detail 是额外信息(JSON/文本)。
	Detail string `gorm:"type:text" json:"detail,omitempty"`

	IP        string `gorm:"size:64" json:"ip,omitempty"`
	UserAgent string `gorm:"size:256" json:"user_agent,omitempty"`

	CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
}

AuditLog stores immutable audit records (no delete API). AuditLog 保存不可变审计记录(不提供删除 API)。

func (AuditLog) TableName

func (AuditLog) TableName() string

TableName 用来显式指定表名(可选)

type AuthToken

type AuthToken struct {
	ID uint `gorm:"primaryKey" json:"id"`

	// JTI is the unique identifier of JWT.
	// JTI 是 JWT 的唯一标识。
	JTI string `gorm:"uniqueIndex;size:64;not null" json:"jti"`

	UserID uint `gorm:"index;not null" json:"user_id"`
	User   User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-"`

	Type TokenType `gorm:"size:16;index;not null" json:"type"`

	// Name is optional token label.
	// Name 是可选的 token 备注。
	Name string `gorm:"size:128" json:"name,omitempty"`

	IssuedAt time.Time `gorm:"not null" json:"issued_at"`

	// ExpiresAt is optional absolute expiration.
	// ExpiresAt 是可选的绝对过期时间。
	ExpiresAt *time.Time `json:"expires_at,omitempty"`

	// LastSeenAt enables sliding idle timeout for web sessions.
	// LastSeenAt 用于 Web 会话的滑动空闲超时。
	LastSeenAt *time.Time `json:"last_seen_at,omitempty"`

	// IdleTimeoutSeconds is used only for web sessions.
	// IdleTimeoutSeconds 仅用于 Web 会话。
	IdleTimeoutSeconds int `gorm:"not null;default:0" json:"idle_timeout_seconds"`

	RevokedAt *time.Time `json:"revoked_at,omitempty"`
	RevokedBy *uint      `json:"revoked_by,omitempty"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

AuthToken stores token metadata (server-side session control). AuthToken 存储 token 元数据(服务端可控会话)。

type Base

type Base struct {
	ID        string `gorm:"primaryKey;column:id;size:36;uniqueIndex;not null" json:"id"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Model a basic GoLang struct which includes the following fields: ID, CreatedAt, UpdatedAt, DeletedAt It may be embedded into your model or you may build your own model without it

type User struct {
  Base
}

func (*Base) BeforeCreate

func (b *Base) BeforeCreate(tx *gorm.DB) error

type Channel

type Channel struct {
	Base
	Delay           time.Duration  `gorm:"column:delay" json:"delay"`                   // 时延 单位 毫秒
	DebugLog        bool           `gorm:"column:debug_log" json:"debug_log"`           // debug log 模式
	DebugExpiry     time.Time      `gorm:"column:debug_expiry" json:"debug_expiry"`     // debuglog 截止时间
	VerifyHeader    bool           `gorm:"column:verify_header" json:"verify_header"`   // 校验报文头
	OnnectTimeout   time.Duration  `gorm:"column:onnect_timeout" json:"onnect_timeout"` // 连接超时时间 (ms),默认 3s
	Downgrade       bool           `gorm:"column:down_grade" json:"down_grade"`         // 设备降级
	RetryMax        uint64         `gorm:"column:retry_max" json:"retry_max"`           // 最大重试次数,发送读指令失败后最大重试次数
	RetryInterval   time.Duration  `gorm:"column:retry_interval" json:"retry_interval"` // 指令重新发送间隔 (ms)
	Endianness      uint           `gorm:"column:endianness" json:"endianness"`         // endianness
	WordOrder       uint           `gorm:"column:word_order" json:"word_order"`         // word ordering
	SendInterval    time.Duration  `gorm:"column:send_interval" json:"send_interval"`   // 指令发送间隔 (ms)
	PhysicalLink    string         `gorm:"column:physical_link" json:"physical_link"`   // serial、RTUclient、RTUserver、TCPclient、TCPserver
	Disable         bool           `gorm:"column:disable" json:"disable"`               // disable
	Plugin          string         `gorm:"column:plugin;size:128;not null" json:"plugin"`
	AddrStart       bool           `gorm:"column:addr_start" json:"addr_start"`
	TCPIPAddr       string         `gorm:"column:tcp_ip_addr" json:"tcp_ip_addr"`
	TCPPort         uint16         `gorm:"column:tcp_port" json:"tcp_port"`
	BackupTCPIPAddr string         `gorm:"column:backup_tcp_ip_addr" json:"backup_tcp_ip_addr"`
	BackupTCPPort   uint16         `gorm:"column:backup_tcp_port" json:"backup_tcp_port"`
	Status          InstanceStatus `gorm:"-" json:"status"`
}

Channel 通道

func GetDefaultChannelRow

func GetDefaultChannelRow(device, device2 string) *Channel

func (*Channel) AfterCreate

func (c *Channel) AfterCreate(tx *gorm.DB) error

func (*Channel) AfterDelete

func (c *Channel) AfterDelete(tx *gorm.DB) error

func (*Channel) AfterSave

func (c *Channel) AfterSave(tx *gorm.DB) error

func (*Channel) AfterUpdate

func (c *Channel) AfterUpdate(tx *gorm.DB) error

func (*Channel) BeforeCreate

func (c *Channel) BeforeCreate(tx *gorm.DB) error

func (*Channel) BeforeDelete

func (c *Channel) BeforeDelete(tx *gorm.DB) error

func (*Channel) BeforeSave

func (c *Channel) BeforeSave(tx *gorm.DB) error

func (*Channel) BeforeUpdate

func (c *Channel) BeforeUpdate(tx *gorm.DB) error

func (Channel) TableName

func (Channel) TableName() string

TableName 用来显式指定表名(可选)

type DeveltypePointBase

type DeveltypePointBase struct {
	Name      string  `gorm:"size:128;;not null"`                // 信号名
	NameCn    string  `gorm:"size:128;;not null"`                // 信号名
	Gain      float64 `gorm:"not null;default:0"`                // 文档里的 Gain
	Unit      string  `gorm:"size:32"`                           // 单位(V, A, kWh, %...)
	RW        string  `gorm:"size:8;not null;default:'RO'"`      // RO / RW / WO
	Address   uint16  `gorm:"not null"`                          // Modbus 地址(手册里的 Address)
	PointType string  `gorm:"size:8;not null;default:'holding'"` // 点位类型
	Quantity  uint32  `gorm:"not null;default:1"`                // 增益
	DataType  string  `gorm:"size:32;not null"`                  // int16/uint16/int32/float32/bool/string...
	ByteOrder string  `gorm:"size:8"`                            // ABCD/BADC/CDAB/DCBA...
	Offset    float64 `gorm:"not null;default:0"`                // offset
	Desc      string  `gorm:"size:128"`                          // Desc
	Disable   bool    `gorm:"not null;default:false"`            // such as
}

type Device

type Device struct {
	ChannelID string
	Base
	Name            string `gorm:"column:name;size:150;uniqueIndex;not null" json:"name"`
	DeviceType      string `gorm:"column:device_type;size:128;not null;index" json:"device_type"` // Requirement #4: weak association by type_key (no FK)
	Transport       string `gorm:"size:16;not null"`                                              // tcp/rtu/rtu_over_tcp...
	Endpoint        string `gorm:"size:256;not null"`                                             // host:port or /dev/ttyS1
	SlaveID         uint   `gorm:"not null;default:1"`
	PollIntervalMs  int    `gorm:"not null;default:1000"`
	SN              string `gorm:"column:sn;size:128;not null" json:"sn"`
	DevicePlugin    string `gorm:"column:device_plugin;size:128;not null" json:"device_plugin"`
	SoftwareVersion string `gorm:"column:software_version;size:128;not null" json:"software_version"`
	Model           string `gorm:"column:model;size:128;not null" json:"model"`
	Disable         bool   `gorm:"column:disable;size:128;not null" json:"disable"`
}

func (Device) TableName

func (Device) TableName() string

TableName 用来显式指定表名(可选)

type DeviceState

type DeviceState struct {
	Online bool `gorm:"-" json:"online"`
}

type DeviceTypePoint

type DeviceTypePoint struct {
	Base
	TypeKey string `gorm:"size:128;uniqueIndex;not null"`
	Model   string `gorm:"size:128"`           // 逆变器/STS
	Index   uint   `json:"index" yaml:"index"` // 点位 index
	DeveltypePointBase
}

func (DeviceTypePoint) TableName

func (DeviceTypePoint) TableName() string

TableName 用来显式指定表名(可选)

type Goose

type Goose struct {
	Base
	Delay         time.Duration  `gorm:"column:delay" json:"delay"`                   // 时延 单位 毫秒
	DebugLog      bool           `gorm:"column:debug_log" json:"debug_log"`           // debug log 模式
	DebugExpiry   time.Time      `gorm:"column:debug_expiry" json:"debug_expiry"`     // debuglog 截止时间
	OnnectTimeout time.Duration  `gorm:"column:onnect_timeout" json:"onnect_timeout"` // 连接超时时间 (ms),默认 3s
	Downgrade     bool           `gorm:"column:down_grade" json:"down_grade"`         // 设备降级
	RetryMax      uint64         `gorm:"column:retry_max" json:"retry_max"`           // 最大重试次数,发送读指令失败后最大重试次数
	RetryInterval time.Duration  `gorm:"column:retry_interval" json:"retry_interval"` // 指令重新发送间隔 (ms)
	Disable       bool           `gorm:"column:disable" json:"disable"`               // disable
	Plugin        string         `gorm:"column:plugin;size:128;not null" json:"plugin"`
	TCPIPAddr     string         `gorm:"column:tcp_ip_addr" json:"tcp_ip_addr"`
	TCPPort       uint16         `gorm:"column:tcp_port" json:"tcp_port"`
	Status        InstanceStatus `gorm:"-" json:"status"`
}

Goose 通道

func (*Goose) AfterCreate

func (c *Goose) AfterCreate(tx *gorm.DB) error

func (*Goose) AfterDelete

func (c *Goose) AfterDelete(tx *gorm.DB) error

func (*Goose) AfterSave

func (c *Goose) AfterSave(tx *gorm.DB) error

func (*Goose) AfterUpdate

func (c *Goose) AfterUpdate(tx *gorm.DB) error

func (*Goose) BeforeCreate

func (c *Goose) BeforeCreate(tx *gorm.DB) error

func (*Goose) BeforeDelete

func (c *Goose) BeforeDelete(tx *gorm.DB) error

func (*Goose) BeforeSave

func (c *Goose) BeforeSave(tx *gorm.DB) error

func (*Goose) BeforeUpdate

func (c *Goose) BeforeUpdate(tx *gorm.DB) error

func (Goose) TableName

func (Goose) TableName() string

TableName 用来显式指定表名(可选)

type InstanceStatus

type InstanceStatus struct {
	Working         bool          `gorm:"-" json:"working"`           // 工作状态
	Linking         bool          `gorm:"-" json:"linking"`           // 连接状态
	CurrentDelay    time.Duration `gorm:"-" json:"current_delay"`     // 当前采集延迟
	BytesSent       uint64        `gorm:"-" json:"bytes_sent"`        // bytes sent
	BytesReceived   uint64        `gorm:"-" json:"bytes_received"`    // bytes received
	PointsToalRead  uint64        `gorm:"-" json:"points_total_read"` // 点位读取数总计
	PointsErrorRead uint64        `gorm:"-" json:"points_error_read"` // 点位读取错误数总计
}

type Kind

type Kind uint8
const (
	KindInvalid Kind = iota
	KindBool
	KindUint16
	KindSint16
	KindUint32
	KindSint32
	KindSint64
	KindUint64
	KindFloat32
	KindFloat64
	KindString
	KindBytes
	KindBitMask
)

func ParseKind

func ParseKind(s string) (Kind, error)

func (Kind) String

func (k Kind) String() string

type LogrusLogger

type LogrusLogger struct {
	Log           *logrus.Entry
	LogLevel      logger.LogLevel
	SlowThreshold time.Duration
}

func NewLogrusLogger

func NewLogrusLogger(log *logrus.Logger) *LogrusLogger

func (*LogrusLogger) Error

func (l *LogrusLogger) Error(ctx context.Context, msg string, args ...interface{})

func (*LogrusLogger) Info

func (l *LogrusLogger) Info(ctx context.Context, msg string, args ...interface{})

func (*LogrusLogger) LogMode

func (l *LogrusLogger) LogMode(level logger.LogLevel) logger.Interface

func (*LogrusLogger) Trace

func (l *LogrusLogger) Trace(
	ctx context.Context,
	begin time.Time,
	fc func() (sql string, rowsAffected int64),
	err error,
)

func (*LogrusLogger) Warn

func (l *LogrusLogger) Warn(ctx context.Context, msg string, args ...interface{})

type MQTT

type MQTT struct {
	Base
	ID            string         `gorm:"primaryKey;column:id;size:36;uniqueIndex;not null" json:"id"`
	Delay         time.Duration  `gorm:"column:delay" json:"delay"`                   // 时延 单位 毫秒
	DebugLog      bool           `gorm:"column:debug_log" json:"debug_log"`           // debug log 模式
	DebugExpiry   time.Time      `gorm:"column:debug_expiry" json:"debug_expiry"`     // debuglog 截止时间
	OnnectTimeout time.Duration  `gorm:"column:onnect_timeout" json:"onnect_timeout"` // 连接超时时间 (ms),默认 3s
	Downgrade     bool           `gorm:"column:down_grade" json:"down_grade"`         // 设备降级
	RetryMax      uint64         `gorm:"column:retry_max" json:"retry_max"`           // 最大重试次数,发送读指令失败后最大重试次数
	RetryInterval time.Duration  `gorm:"column:retry_interval" json:"retry_interval"` // 指令重新发送间隔 (ms)
	Disable       bool           `gorm:"column:disable" json:"disable"`               // disable
	Plugin        string         `gorm:"column:plugin;size:128;not null" json:"plugin"`
	TCPIPAddr     string         `gorm:"column:tcp_ip_addr" json:"tcp_ip_addr"`
	TCPPort       uint16         `gorm:"column:tcp_port" json:"tcp_port"`
	CreatedAt     time.Time      `json:"created_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	Status        InstanceStatus `gorm:"-" json:"status"`
}

MQTT 通道

func (*MQTT) AfterCreate

func (c *MQTT) AfterCreate(tx *gorm.DB) error

func (*MQTT) AfterDelete

func (c *MQTT) AfterDelete(tx *gorm.DB) error

func (*MQTT) AfterSave

func (c *MQTT) AfterSave(tx *gorm.DB) error

func (*MQTT) AfterUpdate

func (c *MQTT) AfterUpdate(tx *gorm.DB) error

func (*MQTT) BeforeCreate

func (c *MQTT) BeforeCreate(tx *gorm.DB) error

func (*MQTT) BeforeDelete

func (c *MQTT) BeforeDelete(tx *gorm.DB) error

func (*MQTT) BeforeSave

func (c *MQTT) BeforeSave(tx *gorm.DB) error

func (*MQTT) BeforeUpdate

func (c *MQTT) BeforeUpdate(tx *gorm.DB) error

func (MQTT) TableName

func (MQTT) TableName() string

TableName 用来显式指定表名(可选)

type ModelInfo

type ModelInfo struct {
	// StructType must be a non-pointer struct type, e.g. reflect.TypeOf(User{})
	StructType reflect.Type

	// Table is resolved by GORM schema (honors TableName() and naming strategy)
	Table string

	// DefaultPreloads are applied on every FindByTablePK call.
	DefaultPreloads []string
}

ModelInfo describes a model type and optional default preloads. ModelInfo:模型类型 + 默认 Preload

type ModelOpt

type ModelOpt func(*ModelInfo)

ModelOpt allows configuring model info at register time. ModelOpt:注册模型时的配置项

func WithDefaultPreloads

func WithDefaultPreloads(paths ...string) ModelOpt

WithDefaultPreloads sets default preloads for this model. WithDefaultPreloads:给该模型设置“默认 Preload 列表”(每次 Find 都会自动 Preload)

type QueryOpt

type QueryOpt func(*queryOptions)

QueryOpt allows customizing query (e.g., extra preloads). QueryOpt:可选的查询配置(例如额外 Preload)

func WithPreloads

func WithPreloads(paths ...string) QueryOpt

WithPreloads adds extra preloads for this query. WithPreloads:为本次查询额外指定 Preload(不影响注册时默认 Preload)

func WithScopes

func WithScopes(scopes ...func(*gorm.DB) *gorm.DB) QueryOpt

WithScopes applies extra gorm scopes for this query. WithScopes:为本次查询额外套用 scopes

type RegAccess

type RegAccess string
const (
	RegRO RegAccess = "RO"
	RegRW RegAccess = "RW"
	RegWO RegAccess = "WO"
)

type RegType

type RegType string
const (
	RegHolding  RegType = "holding"  // 0x03 / 0x06 / 0x10
	RegInput    RegType = "input"    // 0x04
	RegCoil     RegType = "coil"     // 0x01 / 0x05 / 0x0F
	RegDiscrete RegType = "discrete" // 0x02
)

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry maps DB table name -> model schema/type. Registry:tableName -> model 类型/信息

func NewRegistry

func NewRegistry() *Registry

func (*Registry) FindByTablePK

func (r *Registry) FindByTablePK(ctx context.Context, db *gorm.DB, table string, pkValue any) (any, error)

FindByTablePK only needs table + pkValue. It will query using db.Model(&T{}).First(&T{}, pkValue) to keep soft delete/default scopes/hooks. FindByTablePK:只传 table + pkValue;内部用 Model(&T{}) + First(pk) 方式查询

func (*Registry) FindByTablePKValue

func (r *Registry) FindByTablePKValue(ctx context.Context, db *gorm.DB, table string, pkValue any) (any, error)

FindByTablePKValue returns a non-pointer struct value (T) instead of *T. FindByTablePKValue:返回 struct 值(非指针)

func (*Registry) FindByTablePKWith

func (r *Registry) FindByTablePKWith(ctx context.Context, db *gorm.DB, table string, pkValue any, qopts ...QueryOpt) (any, error)

FindByTablePKWith is the same as FindByTablePK, but allows optional preloads/scopes. FindByTablePKWith:在只传 table+pkValue 的基础上,允许可选 Preload/Scope

func (*Registry) Register

func (r *Registry) Register(db *gorm.DB, model any, opts ...ModelOpt) error

Register parses GORM schema to resolve the table name and registers model type. Register:注册模型(解析 TableName()/命名策略得到 table 名)

type Scalar

type Scalar struct {
	Kind Kind   `json:"kind"`
	Raw  []byte `json:"raw"` // raw bytes, format depends on Kind
}

Scalar stores a typed value in raw bytes.

func (Scalar) Bool

func (s Scalar) Bool() (bool, error)

func (Scalar) Bytes

func (s Scalar) Bytes() ([]byte, error)

func (Scalar) Equal

func (s Scalar) Equal(other Scalar) bool

Helper: compare raw bytes (optional)

func (Scalar) Float32

func (s Scalar) Float32() (float32, error)

func (Scalar) Float64

func (s Scalar) Float64() (float64, error)

func (*Scalar) IsZero

func (s *Scalar) IsZero() bool

func (Scalar) MarshalJSON

func (s Scalar) MarshalJSON() ([]byte, error)

func (*Scalar) Reset

func (s *Scalar) Reset()

func (*Scalar) Scan

func (s *Scalar) Scan(src any) error

func (*Scalar) SetBool

func (s *Scalar) SetBool(v bool)

func (*Scalar) SetBytes

func (s *Scalar) SetBytes(v []byte)

func (*Scalar) SetFloat32

func (s *Scalar) SetFloat32(v float32)

func (*Scalar) SetFloat64

func (s *Scalar) SetFloat64(v float64)

func (*Scalar) SetSint16

func (s *Scalar) SetSint16(v int16)

func (*Scalar) SetSint32

func (s *Scalar) SetSint32(v int32)

func (*Scalar) SetSint64

func (s *Scalar) SetSint64(v int64)

func (*Scalar) SetString

func (s *Scalar) SetString(v string)

func (*Scalar) SetUint16

func (s *Scalar) SetUint16(v uint16)

func (*Scalar) SetUint32

func (s *Scalar) SetUint32(v uint32)

func (*Scalar) SetUint64

func (s *Scalar) SetUint64(v uint64)

func (Scalar) Sint16

func (s Scalar) Sint16() (int16, error)

func (Scalar) Sint32

func (s Scalar) Sint32() (int32, error)

func (Scalar) Sint64

func (s Scalar) Sint64() (int64, error)

func (Scalar) String

func (s Scalar) String() (string, error)

func (Scalar) Uint16

func (s Scalar) Uint16() (uint16, error)

func (Scalar) Uint32

func (s Scalar) Uint32() (uint32, error)

func (Scalar) Uint64

func (s Scalar) Uint64() (uint64, error)

func (*Scalar) UnmarshalJSON

func (s *Scalar) UnmarshalJSON(b []byte) error

func (Scalar) Value

func (s Scalar) Value() (driver.Value, error)

type ScalarJSON

type ScalarJSON []byte

ScalarJSON stores any JSON value (scalar/object/array) safely. ScalarJSON 用于安全存放任意 JSON 值(标量/对象/数组),避免 JSONB 标量 Scan 失败。

func (*ScalarJSON) Scan

func (j *ScalarJSON) Scan(src any) error

Scan implements sql.Scanner / 实现 sql.Scanner

func (ScalarJSON) Value

func (j ScalarJSON) Value() (driver.Value, error)

Value implements driver.Valuer / 实现 driver.Valuer

type Serial

type Serial struct {
	ID            string         `gorm:"primaryKey;column:id;size:36;uniqueIndex;not null" json:"id"`
	Delay         time.Duration  `gorm:"column:delay" json:"delay"`                     // 时延 单位 毫秒
	DebugLog      bool           `gorm:"column:debug_log" json:"debug_log"`             // debug log 模式
	DebugExpiry   time.Time      `gorm:"column:debug_expiry" json:"debug_expiry"`       // debuglog 截止时间
	VerifyHeader  bool           `gorm:"column:verify_header" json:"verify_header"`     // 校验报文头
	OnnectTimeout time.Duration  `gorm:"column:onnect_timeout" json:"onnect_timeout"`   // 连接超时时间 (ms),默认 3s
	Downgrade     bool           `gorm:"column:down_grade" json:"down_grade"`           // 设备降级
	RetryMax      uint64         `gorm:"column:retry_max" json:"retry_max"`             // 最大重试次数,发送读指令失败后最大重试次数
	RetryInterval time.Duration  `gorm:"column:retry_interval" json:"retry_interval"`   // 指令重新发送间隔 (ms)
	Endianness    uint           `gorm:"column:endianness" json:"endianness"`           // endianness
	WordOrder     uint           `gorm:"column:word_order" json:"word_order"`           // word ordering
	SendInterval  time.Duration  `gorm:"column:send_interval" json:"send_interval"`     // 指令发送间隔 (ms)
	PhysicalLink  string         `gorm:"column:physical_link" json:"physical_link"`     // serial、RTUclient、RTUserver、TCPclient、TCPserver
	Disable       bool           `gorm:"column:disable" json:"disable"`                 // disable
	Plugin        string         `gorm:"column:plugin;size:128;not null" json:"plugin"` // plugin
	Device        string         `gorm:"uniqueIndex;size:256;not null" json:"device"`   // Device is like "/dev/ttyUSB0" / 设备路径,例如 "/dev/ttyUSB0"
	Device2       string         `gorm:"uniqueIndex;size:256;not null" json:"device2"`  // Device is like "/dev/ttyUSB0" / 设备路径,例如 "/dev/ttyUSB1"
	StopBits      uint           `gorm:"column:stop_bits" json:"stop_bits"`             // 停止位
	Speed         uint           `gorm:"column:speed" json:"speed"`                     // speed
	DataBits      uint           `gorm:"column:data_bits" json:"data_bits"`             // data bits
	Parity        uint           `gorm:"column:parity" json:"parity"`                   // parity
	CreatedAt     time.Time      `json:"created_at"`
	UpdatedAt     time.Time      `json:"updated_at"`
	Status        InstanceStatus `gorm:"-" json:"status"`
}

Serial 通道

func GetDefaultSerialRow

func GetDefaultSerialRow(device, device2 string) *Serial

func (*Serial) AfterCreate

func (c *Serial) AfterCreate(tx *gorm.DB) error

func (*Serial) AfterDelete

func (c *Serial) AfterDelete(tx *gorm.DB) error

func (*Serial) AfterSave

func (c *Serial) AfterSave(tx *gorm.DB) error

func (*Serial) AfterUpdate

func (c *Serial) AfterUpdate(tx *gorm.DB) error

func (*Serial) BeforeCreate

func (c *Serial) BeforeCreate(tx *gorm.DB) error

func (*Serial) BeforeDelete

func (c *Serial) BeforeDelete(tx *gorm.DB) error

func (*Serial) BeforeSave

func (c *Serial) BeforeSave(tx *gorm.DB) error

func (*Serial) BeforeUpdate

func (c *Serial) BeforeUpdate(tx *gorm.DB) error

func (Serial) TableName

func (Serial) TableName() string

TableName 用来显式指定表名(可选)

type Setting

type Setting struct {
	// UUID string primary key
	// UUID 字符串主键
	ID string `json:"id" gorm:"primaryKey;type:char(36)"`

	// Unique key name
	// 唯一配置名
	Name string `json:"name" gorm:"size:128;uniqueIndex;not null"`

	// Discriminator for value type: int|string|bool
	// 值类型判别字段:int|string|bool
	ValueType string `json:"value_type" gorm:"size:16;not null;index"`

	// ValueJSON stores raw JSON scalar (10/"abc"/true) / 原始 JSON 标量
	ValueJSON ScalarJSON `json:"value_json" gorm:"type:jsonb;not null" swaggertype:"string" example:"10"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

Setting 系统配置表 Setting represents system settings table.

value_json 存放 JSON 原始值:可以是 number/string/bool value_type 作为判别字段:int/string/bool

func (*Setting) BeforeCreate

func (s *Setting) BeforeCreate(tx *gorm.DB) error

BeforeCreate 在创建前生成 UUID / generate UUID before insert.

func (Setting) TableName

func (Setting) TableName() string

TableName 指定表名 / TableName specifies table name.

type Site

type Site struct {
	gorm.Model
	UUID        string    `gorm:"primaryKey;column:uuid;size:36;uniqueIndex;not null" json:"uuid"`
	Name        string    `gorm:"column:name;size:1024;uniqueIndex;not null" json:"name"`
	Power       uint64    // 电站额定充放电功率,单位 瓦特
	Store       uint64    // 电站额定储能容量,单位 瓦特H
	GridConTime time.Time // 并网/启用时间
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func (Site) TableName

func (Site) TableName() string

TableName 用来显式指定表名(可选)

type TokenType

type TokenType string

TokenType defines token categories. TokenType 定义 token 分类。

const (
	// TokenTypeWeb is for web login sessions (idle-timeout).
	// TokenTypeWeb 用于 Web 登录会话(空闲超时)。
	TokenTypeWeb TokenType = "web"

	// TokenTypeAPI is for permanent API token (PAT-like).
	// TokenTypeAPI 用于永久 API Token(类似 PAT)。
	TokenTypeAPI TokenType = "api"
)

type User

type User struct {
	ID           uint       `gorm:"primaryKey" json:"id"`
	Username     string     `gorm:"uniqueIndex;size:64;not null" json:"username"`
	PasswordHash string     `gorm:"size:255;not null" json:"-"`
	IsRoot       bool       `gorm:"not null;default:false" json:"is_root"`
	LastLogin    *time.Time `json:"last_login"`
	CreatedAt    time.Time  `json:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at"`
}

User represents a local account. User 表示本地账号。

func (User) TableName

func (User) TableName() string

TableName 用来显式指定表名(可选)

Jump to

Keyboard shortcuts

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