schema

package
v10.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MenuStatusDisabled = "disabled"
	MenuStatusEnabled  = "enabled"
)
View Source
const (
	RoleStatusEnabled  = "enabled"  // Enabled
	RoleStatusDisabled = "disabled" // Disabled

	RoleResultTypeSelect = "select" // Select
)
View Source
const (
	UserStatusActivated = "activated"
	UserStatusFreezed   = "freezed"
)

Variables

View Source
var (
	MenusOrderParams = []util.OrderByParam{
		{Field: "sequence", Direction: util.DESC},
		{Field: "created_at", Direction: util.DESC},
	}
)

Functions

This section is empty.

Types

type Captcha

type Captcha struct {
	CaptchaID string `json:"captcha_id"` // Captcha ID
}

type LoginForm

type LoginForm struct {
	Username    string `json:"username" binding:"required"`     // Login name
	Password    string `json:"password" binding:"required"`     // Login password (md5 hash)
	CaptchaID   string `json:"captcha_id" binding:"required"`   // Captcha verify id
	CaptchaCode string `json:"captcha_code" binding:"required"` // Captcha verify code
}

func (*LoginForm) Trim

func (a *LoginForm) Trim() *LoginForm

type LoginToken

type LoginToken struct {
	AccessToken string `json:"access_token"` // Access token (JWT)
	TokenType   string `json:"token_type"`   // Token type (Usage: Authorization=${token_type} ${access_token})
	ExpiresAt   int64  `json:"expires_at"`   // Expired time (Unit: second)
}
type Menu struct {
	ID          string        `json:"id" gorm:"size:20;primarykey;"`      // Unique ID
	Code        string        `json:"code" gorm:"size:32;index;"`         // Code of menu (unique for each level)
	Name        string        `json:"name" gorm:"size:128;index"`         // Display name of menu
	Description string        `json:"description" gorm:"size:1024"`       // Details about menu
	Sequence    int           `json:"sequence" gorm:"index;"`             // Sequence for sorting (Order by desc)
	Type        string        `json:"type" gorm:"size:20;index"`          // Type of menu (page, button)
	Path        string        `json:"path" gorm:"size:255;"`              // Access path of menu
	Properties  string        `json:"properties" gorm:"type:text;"`       // Properties of menu (JSON)
	Status      string        `json:"status" gorm:"size:20;index"`        // Status of menu (enabled, disabled)
	ParentID    string        `json:"parent_id" gorm:"size:20;index;"`    // Parent ID (From Menu.ID)
	ParentPath  string        `json:"parent_path" gorm:"size:255;index;"` // Parent path (split by .)
	Children    *Menus        `json:"children" gorm:"-"`                  // Child menus
	CreatedAt   time.Time     `json:"created_at" gorm:"index;"`           // Create time
	UpdatedAt   time.Time     `json:"updated_at" gorm:"index;"`           // Update time
	Resources   MenuResources `json:"resources" gorm:"-"`                 // Resources of menu
}

Menu management for RBAC

func (a *Menu) TableName() string
type MenuForm struct {
	Code        string        `json:"code" binding:"required,max=32"`                   // Code of menu (unique for each level)
	Name        string        `json:"name" binding:"required,max=128"`                  // Display name of menu
	Description string        `json:"description"`                                      // Details about menu
	Sequence    int           `json:"sequence"`                                         // Sequence for sorting (Order by desc)
	Type        string        `json:"type" binding:"required,oneof=page button"`        // Type of menu (page, button)
	Path        string        `json:"path"`                                             // Access path of menu
	Properties  string        `json:"properties"`                                       // Properties of menu (JSON)
	Status      string        `json:"status" binding:"required,oneof=disabled enabled"` // Status of menu (enabled, disabled)
	ParentID    string        `json:"parent_id"`                                        // Parent ID (From Menu.ID)
	Resources   MenuResources `json:"resources"`                                        // Resources of menu
}

Defining the data structure for creating a `Menu` struct.

func (a *MenuForm) FillTo(menu *Menu) error
func (a *MenuForm) Validate() error

A validation function for the `MenuForm` struct.

type MenuQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `Menu` struct.

type MenuQueryParam struct {
	util.PaginationParam
	CodePath         string   `form:"code"`             // Code path (like xxx.xxx.xxx)
	LikeName         string   `form:"name"`             // Display name of menu
	IncludeResources bool     `form:"includeResources"` // Include resources
	InIDs            []string `form:"-"`                // Include menu IDs
	Status           string   `form:"-"`                // Status of menu (disabled, enabled)
	ParentID         string   `form:"-"`                // Parent ID (From Menu.ID)
	ParentPathPrefix string   `form:"-"`                // Parent path (split by .)
	UserID           string   `form:"-"`                // User ID
	RoleID           string   `form:"-"`                // Role ID
}

Defining the query parameters for the `Menu` struct.

type MenuQueryResult struct {
	Data       Menus
	PageResult *util.PaginationResult
}

Defining the query result for the `Menu` struct.

type MenuResource struct {
	ID        string    `json:"id" gorm:"size:20;primarykey"` // Unique ID
	MenuID    string    `json:"menu_id" gorm:"size:20;index"` // From Menu.ID
	Method    string    `json:"method" gorm:"size:20;"`       // HTTP method
	Path      string    `json:"path" gorm:"size:255;"`        // API request path (e.g. /api/v1/users/:id)
	CreatedAt time.Time `json:"created_at" gorm:"index;"`     // Create time
	UpdatedAt time.Time `json:"updated_at" gorm:"index;"`     // Update time
}

Menu resource management for RBAC

func (a *MenuResource) TableName() string
type MenuResourceForm struct {
}

Defining the data structure for creating a `MenuResource` struct.

func (a *MenuResourceForm) FillTo(menuResource *MenuResource) error
func (a *MenuResourceForm) Validate() error

A validation function for the `MenuResourceForm` struct.

type MenuResourceQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `MenuResource` struct.

type MenuResourceQueryParam struct {
	util.PaginationParam
	MenuID  string   `form:"-"` // From Menu.ID
	MenuIDs []string `form:"-"` // From Menu.ID
}

Defining the query parameters for the `MenuResource` struct.

type MenuResourceQueryResult struct {
	Data       MenuResources
	PageResult *util.PaginationResult
}

Defining the query result for the `MenuResource` struct.

type MenuResources []*MenuResource

Defining the slice of `MenuResource` struct.

type Menus []*Menu

Defining the slice of `Menu` struct.

func (a Menus) Len() int
func (a Menus) Less(i, j int) bool
func (a Menus) SplitParentIDs() []string
func (a Menus) Swap(i, j int)
func (a Menus) ToMap() map[string]*Menu
func (a Menus) ToTree() Menus

type Role

type Role struct {
	ID          string    `json:"id" gorm:"size:20;primarykey;"` // Unique ID
	Code        string    `json:"code" gorm:"size:32;index;"`    // Code of role (unique)
	Name        string    `json:"name" gorm:"size:128;index"`    // Display name of role
	Description string    `json:"description" gorm:"size:1024"`  // Details about role
	Sequence    int       `json:"sequence" gorm:"index"`         // Sequence for sorting
	Status      string    `json:"status" gorm:"size:20;index"`   // Status of role (disabled, enabled)
	CreatedAt   time.Time `json:"created_at" gorm:"index;"`      // Create time
	UpdatedAt   time.Time `json:"updated_at" gorm:"index;"`      // Update time
	Menus       RoleMenus `json:"menus" gorm:"-"`                // Role menu list
}

Role management for RBAC

func (*Role) TableName

func (a *Role) TableName() string

type RoleForm

type RoleForm struct {
	Code        string    `json:"code" binding:"required,max=32"`                   // Code of role (unique)
	Name        string    `json:"name" binding:"required,max=128"`                  // Display name of role
	Description string    `json:"description"`                                      // Details about role
	Sequence    int       `json:"sequence"`                                         // Sequence for sorting
	Status      string    `json:"status" binding:"required,oneof=disabled enabled"` // Status of role (enabled, disabled)
	Menus       RoleMenus `json:"menus"`                                            // Role menu list
}

Defining the data structure for creating a `Role` struct.

func (*RoleForm) FillTo

func (a *RoleForm) FillTo(role *Role) error

func (*RoleForm) Validate

func (a *RoleForm) Validate() error

A validation function for the `RoleForm` struct.

type RoleMenu

type RoleMenu struct {
	ID        string    `json:"id" gorm:"size:20;primarykey"` // Unique ID
	RoleID    string    `json:"role_id" gorm:"size:20;index"` // From Role.ID
	MenuID    string    `json:"menu_id" gorm:"size:20;index"` // From Menu.ID
	CreatedAt time.Time `json:"created_at" gorm:"index;"`     // Create time
	UpdatedAt time.Time `json:"updated_at" gorm:"index;"`     // Update time
}

Role permissions for RBAC

func (*RoleMenu) TableName

func (a *RoleMenu) TableName() string

type RoleMenuForm

type RoleMenuForm struct {
}

Defining the data structure for creating a `RoleMenu` struct.

func (*RoleMenuForm) FillTo

func (a *RoleMenuForm) FillTo(roleMenu *RoleMenu) error

func (*RoleMenuForm) Validate

func (a *RoleMenuForm) Validate() error

A validation function for the `RoleMenuForm` struct.

type RoleMenuQueryOptions

type RoleMenuQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `RoleMenu` struct.

type RoleMenuQueryParam

type RoleMenuQueryParam struct {
	util.PaginationParam
	RoleID string `form:"-"` // From Role.ID
}

Defining the query parameters for the `RoleMenu` struct.

type RoleMenuQueryResult

type RoleMenuQueryResult struct {
	Data       RoleMenus
	PageResult *util.PaginationResult
}

Defining the query result for the `RoleMenu` struct.

type RoleMenus

type RoleMenus []*RoleMenu

Defining the slice of `RoleMenu` struct.

type RoleQueryOptions

type RoleQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `Role` struct.

type RoleQueryParam

type RoleQueryParam struct {
	util.PaginationParam
	LikeName    string     `form:"name"`                                       // Display name of role
	Status      string     `form:"status" binding:"oneof=disabled enabled ''"` // Status of role (disabled, enabled)
	ResultType  string     `form:"resultType"`                                 // Result type (options: select)
	InIDs       []string   `form:"-"`                                          // ID list
	GtUpdatedAt *time.Time `form:"-"`                                          // Update time is greater than
}

Defining the query parameters for the `Role` struct.

type RoleQueryResult

type RoleQueryResult struct {
	Data       Roles
	PageResult *util.PaginationResult
}

Defining the query result for the `Role` struct.

type Roles

type Roles []*Role

Defining the slice of `Role` struct.

type UpdateCurrentUser

type UpdateCurrentUser struct {
	Name   string `json:"name" binding:"required,max=64"` // Name of user
	Phone  string `json:"phone" binding:"max=32"`         // Phone number of user
	Email  string `json:"email" binding:"max=128"`        // Email of user
	Remark string `json:"remark" binding:"max=1024"`      // Remark of user
}

type UpdateLoginPassword

type UpdateLoginPassword struct {
	OldPassword string `json:"old_password" binding:"required"` // Old password (md5 hash)
	NewPassword string `json:"new_password" binding:"required"` // New password (md5 hash)
}

type User

type User struct {
	ID        string    `json:"id" gorm:"size:20;primarykey;"` // Unique ID
	Username  string    `json:"username" gorm:"size:64;index"` // Username for login
	Name      string    `json:"name" gorm:"size:64;index"`     // Name of user
	Password  string    `json:"-" gorm:"size:64;"`             // Password for login (encrypted)
	Phone     string    `json:"phone" gorm:"size:32;"`         // Phone number of user
	Email     string    `json:"email" gorm:"size:128;"`        // Email of user
	Remark    string    `json:"remark" gorm:"size:1024;"`      // Remark of user
	Status    string    `json:"status" gorm:"size:20;index"`   // Status of user (activated, freezed)
	CreatedAt time.Time `json:"created_at" gorm:"index;"`      // Create time
	UpdatedAt time.Time `json:"updated_at" gorm:"index;"`      // Update time
	Roles     UserRoles `json:"roles" gorm:"-"`                // Roles of user
}

User management for RBAC

func (*User) TableName

func (a *User) TableName() string

type UserForm

type UserForm struct {
	Username string    `json:"username" binding:"required,max=64"`                // Username for login
	Name     string    `json:"name" binding:"required,max=64"`                    // Name of user
	Password string    `json:"password" binding:"max=64"`                         // Password for login (md5 hash)
	Phone    string    `json:"phone" binding:"max=32"`                            // Phone number of user
	Email    string    `json:"email" binding:"max=128"`                           // Email of user
	Remark   string    `json:"remark" binding:"max=1024"`                         // Remark of user
	Status   string    `json:"status" binding:"required,oneof=activated freezed"` // Status of user (activated, freezed)
	Roles    UserRoles `json:"roles" binding:"required"`                          // Roles of user
}

Defining the data structure for creating a `User` struct.

func (*UserForm) FillTo

func (a *UserForm) FillTo(user *User) error

Convert `UserForm` to `User` object.

func (*UserForm) Validate

func (a *UserForm) Validate() error

A validation function for the `UserForm` struct.

type UserQueryOptions

type UserQueryOptions struct {
	util.QueryOptions
}

Defining the query options for the `User` struct.

type UserQueryParam

type UserQueryParam struct {
	util.PaginationParam
	LikeUsername string `form:"username"`                                    // Username for login
	LikeName     string `form:"name"`                                        // Name of user
	Status       string `form:"status" binding:"oneof=activated freezed ''"` // Status of user (activated, freezed)
}

Defining the query parameters for the `User` struct.

type UserQueryResult

type UserQueryResult struct {
	Data       Users
	PageResult *util.PaginationResult
}

Defining the query result for the `User` struct.

type UserRole

type UserRole struct {
	ID        string    `json:"id" gorm:"size:20;primarykey"`           // Unique ID
	UserID    string    `json:"user_id" gorm:"size:20;index"`           // From User.ID
	RoleID    string    `json:"role_id" gorm:"size:20;index"`           // From Role.ID
	CreatedAt time.Time `json:"created_at" gorm:"index;"`               // Create time
	UpdatedAt time.Time `json:"updated_at" gorm:"index;"`               // Update time
	RoleName  string    `json:"role_name" gorm:"<-:false;-:migration;"` // From Role.Name
}

User roles for RBAC

func (*UserRole) TableName

func (a *UserRole) TableName() string

type UserRoleForm

type UserRoleForm struct {
}

Defining the data structure for creating a `UserRole` struct.

func (*UserRoleForm) FillTo

func (a *UserRoleForm) FillTo(userRole *UserRole) error

func (*UserRoleForm) Validate

func (a *UserRoleForm) Validate() error

A validation function for the `UserRoleForm` struct.

type UserRoleQueryOptions

type UserRoleQueryOptions struct {
	util.QueryOptions
	JoinRole bool // Join role table
}

Defining the query options for the `UserRole` struct.

type UserRoleQueryParam

type UserRoleQueryParam struct {
	util.PaginationParam
	InUserIDs []string `form:"-"` // From User.ID
	UserID    string   `form:"-"` // From User.ID
	RoleID    string   `form:"-"` // From Role.ID
}

Defining the query parameters for the `UserRole` struct.

type UserRoleQueryResult

type UserRoleQueryResult struct {
	Data       UserRoles
	PageResult *util.PaginationResult
}

Defining the query result for the `UserRole` struct.

type UserRoles

type UserRoles []*UserRole

Defining the slice of `UserRole` struct.

func (UserRoles) ToRoleIDs

func (a UserRoles) ToRoleIDs() []string

func (UserRoles) ToUserIDMap

func (a UserRoles) ToUserIDMap() map[string]UserRoles

type Users

type Users []*User

Defining the slice of `User` struct.

func (Users) ToIDs

func (a Users) ToIDs() []string

Jump to

Keyboard shortcuts

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