Documentation
¶
Index ¶
Constants ¶
const ( // Directory is a menu directory (a grouping node with no page of its own). Directory string = "M" // Menu is a page menu entry. Menu string = "C" // Button is a button-level permission entry. Button string = "F" )
Menu type enum values used by sys_menu.menu_type.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActiveRecord ¶
type ActiveRecord interface {
schema.Tabler
SetCreateBy(createBy int)
SetUpdateBy(updateBy int)
Generate() ActiveRecord
GetId() interface{}
}
ActiveRecord is what the framework's generic CRUD Actions require of a model. It is self-referencing (Generate returns ActiveRecord), which is exactly why it must stay a type alias on the go-admin side rather than a defined type: a defined type breaks the method set every implementer needs to satisfy this interface. See sdk/contract/models's package doc test for the counterproof.
type BaseUser ¶
type BaseUser struct {
Username string `json:"username" gorm:"type:varchar(100);comment:username"`
Salt string `json:"-" gorm:"type:varchar(255);comment:salt;<-"`
PasswordHash string `json:"-" gorm:"type:varchar(128);comment:password hash;<-"`
Password string `json:"password" gorm:"-"`
}
BaseUser is the embeddable base for a password-login user model.
func (*BaseUser) GetPasswordHash ¶
GetPasswordHash derives the hash for the current Password and Salt.
func (*BaseUser) SetPassword ¶
SetPassword sets the plaintext password, generating a fresh salt and deriving the stored hash from it.
func (*BaseUser) Verify ¶
Verify loads the row matching u.Username from tableName and reports whether u.Password (already hashed into PasswordHash via SetPassword) matches what is stored.
A failed lookup must return false, never fall through to the comparison. First leaves the receiver untouched when it finds no row, so a caller that reuses a receiver already loaded from an earlier successful login would otherwise compare that stale Salt and PasswordHash against themselves and verify true for a username that does not exist.
type ControlBy ¶
type ControlBy struct {
CreateBy int `json:"createBy" gorm:"index;comment:creator"`
UpdateBy int `json:"updateBy" gorm:"index;comment:updater"`
}
ControlBy holds who created and who last updated a row. Embed it in any model whose writes go through the framework's CRUD Actions or hand-written Services: actions.Permission's data-scope SQL joins on CreateBy, so a model without this embed makes every data-scope rule silently match nothing.
func (*ControlBy) SetCreateBy ¶
SetCreateBy sets the id of the user who created the row.
func (*ControlBy) SetUpdateBy ¶
SetUpdateBy sets the id of the user who last updated the row.
type Migration ¶
type Migration struct {
Version string `gorm:"primaryKey"`
ApplyTime time.Time `gorm:"autoCreateTime"`
// AppCode identifies which app registered this migration. The empty
// string means the framework itself.
//
// NOT NULL DEFAULT ” rather than a nullable column, and the difference
// is not cosmetic: on a nullable column the rows that already exist when
// AutoMigrate adds it hold NULL, and the first SELECT scanning one into
// this string field fails with "converting NULL to string is
// unsupported". The default is what makes "existing history belongs to
// the framework" true without a backfill script anyone could forget to
// run.
AppCode string `gorm:"type:varchar(64);not null;default:'';index:idx_sys_migration_app_code;comment:AppCode"`
}
Migration is the sys_migration row model: one row per applied migration. It is unrelated to sdk/contract/migration.Registry (the in-process registration table); the two share a name only because both are called "migration" in their own vocabulary — this one is data, that one is code.
type Model ¶
type Model struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:primary key"`
}
Model is the primary key embed shared by every framework-managed table.
type ModelTime ¶
type ModelTime struct {
CreatedAt time.Time `json:"createdAt" gorm:"comment:creation time"`
UpdatedAt time.Time `json:"updatedAt" gorm:"comment:last updated time"`
// DeletedAt is milliseconds since the epoch, zero while the row is live,
// and never null.
//
// A nullable marker cannot take part in a unique index. Two live rows are
// (name, NULL) and (name, NULL), and NULL is not equal to NULL, so the
// index permits both — it looks like a constraint and enforces nothing.
// With zero for live rows the pair collides, while two deletions of the
// same name differ by their timestamps and both remain.
DeletedAt soft_delete.DeletedAt `json:"-" gorm:"softDelete:milli;index;comment:deletion time"`
}
ModelTime holds the created/updated/deleted timestamps every framework table carries.
type Page ¶
type Page struct {
List interface{} `json:"list"`
Count int `json:"count"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize"`
}
Page wraps a list result with its pagination metadata.
type Response ¶
type Response struct {
// Code is the business status code.
Code int `json:"code" example:"200"`
// Data is the payload.
Data interface{} `json:"data"`
// Msg is a human-readable message.
Msg string `json:"msg"`
RequestId string `json:"requestId"`
}
Response is the envelope go-admin's handlers wrap every JSON reply in.
func (*Response) ReturnError ¶
ReturnError marks the response as failed with the given code.