biz

package
v0.0.0-...-1b17b00 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheNSForUser = "user"
	CacheNSForRole = "role"
)
View Source
const (
	ErrInvalidTokenID            = "com.invalid.token"
	ErrInvalidCaptchaID          = "com.invalid.captcha"
	ErrInvalidUsernameOrPassword = "com.invalid.username-or-password"
)
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"
)
View Source
const (
	CacheKeyForSyncToCasbin = "sync:casbin"
)
View Source
const MaxPullTaskCount = 200

MaxPullTaskCount max pull task count by planId, generally 200 is enough

View Source
const (
	PopWaitSecond = 10
)

Variables

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

Functions

This section is empty.

Types

type BindConn

type BindConn struct {
	Nums []int32
	Addr string
	// contains filtered or unexported fields
}

stress

type BindNode

type BindNode struct {
	Nums []int32
	// contains filtered or unexported fields
}

stress

type Bucket

type Bucket struct {
	Mark      int
	Count     int64
	Frequency float64
}

record

type CaptchaResult

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

login

type CasbinUsecase

type CasbinUsecase struct {
	Enforcer *atomic.Value `wire:"-"`
	// contains filtered or unexported fields
}

func NewCasbinUsecase

func NewCasbinUsecase(
	cache cachex.Cache,
	menuRepository MenuRepository,
	roleRepository RoleRepository,
	menuResourceRepository MenuResourceRepository,
	conf *conf.ServerConf,
) *CasbinUsecase

NewCasbinUsecase initializes a new CasbinUsecase with the given parameters.

cache: cachex.Cache menuRepository: MenuRepository roleRepository: RoleRepository menuResourceRepository: MenuResourceRepository conf: *conf.ServerConf Returns *CasbinUsecase

func (*CasbinUsecase) GetEnforcer

func (a *CasbinUsecase) GetEnforcer() *casbin.Enforcer

func (*CasbinUsecase) Load

func (a *CasbinUsecase) Load(ctx context.Context) error

func (*CasbinUsecase) Release

func (a *CasbinUsecase) Release(ctx context.Context) error

type DynamicParam

type DynamicParam struct {
	Headers map[string]string
	Query   map[string]string
	Body    string
}

stress

type Entry

type Entry struct {
	EntryKey   string `json:"entry_key"`
	EntryValue string `json:"entry_value"`
}

stress

type JsonBody

type JsonBody struct {
	Json map[string]any `json:"json"`
}

record

type LatencyDistribution

type LatencyDistribution struct {
	Percentage    float64
	Latency       int
	PercentageStr string
	LatencyMs     string
}

record

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
}

login

func (*LoginForm) Trim

func (a *LoginForm) Trim() *LoginForm

type LoginResult

type LoginResult 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)
}

login

type LoginUsecase

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

func NewLoginUsecase

func NewLoginUsecase(
	cache cachex.Cache,
	conf *conf.ServerConf,
	userRepository UserRepository,
	auth jwtx.Auther,
	userUsecase *UserUsecase,
	userRoleRepository UserRoleRepository,
	menuRepository MenuRepository,
) *LoginUsecase

func (*LoginUsecase) GetCaptcha

func (u *LoginUsecase) GetCaptcha(ctx context.Context) (CaptchaResult, error)

func (*LoginUsecase) GetUserInfo

func (u *LoginUsecase) GetUserInfo(ctx context.Context) (*User, error)

func (*LoginUsecase) Login

func (u *LoginUsecase) Login(ctx context.Context, formItem *LoginForm) (*LoginResult, error)

func (*LoginUsecase) Logout

func (u *LoginUsecase) Logout(ctx context.Context) error

func (*LoginUsecase) ParseUserID

func (u *LoginUsecase) ParseUserID(c *gin.Context) (string, error)

ParseUserID parse user id for middleware

func (*LoginUsecase) QueryMenus

func (u *LoginUsecase) QueryMenus(ctx context.Context) (Menus, error)

func (*LoginUsecase) RefreshToken

func (u *LoginUsecase) RefreshToken(ctx context.Context) (*LoginResult, error)

func (*LoginUsecase) ResponseCaptcha

func (u *LoginUsecase) ResponseCaptcha(ctx context.Context, w http.ResponseWriter, id string, reload bool) error

ResponseCaptcha Response captcha image

func (*LoginUsecase) UpdatePassword

func (u *LoginUsecase) UpdatePassword(ctx context.Context, updateItem *UpdateLoginPassword) error

func (*LoginUsecase) UpdateUser

func (u *LoginUsecase) UpdateUser(ctx context.Context, updateItem *UpdateCurrentUser) error
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
}
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
}
func (a *MenuForm) FillTo(menu *Menu) error
func (a *MenuForm) Validate() error

Validate A validation function for the `MenuForm` struct.

type MenuQueryOptions struct {
	common.QueryOptions
}
type MenuQueryParam struct {
	common.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
}
type MenuQueryResult struct {
	Data       Menus
	PageResult *common.PaginationResult
}
type MenuRepository interface {
	Query(ctx context.Context, params MenuQueryParam, opts ...MenuQueryOptions) (*MenuQueryResult, error)
	Get(ctx context.Context, id string, opts ...MenuQueryOptions) (*Menu, error)
	GetByCodeAndParentID(ctx context.Context, code, parentID string, opts ...MenuQueryOptions) (*Menu, error)
	GetByNameAndParentID(ctx context.Context, name, parentID string, opts ...MenuQueryOptions) (*Menu, error)
	Exists(ctx context.Context, id string) (bool, error)
	ExistsCodeByParentID(ctx context.Context, code, parentID string) (bool, error)
	ExistsNameByParentID(ctx context.Context, name, parentID string) (bool, error)
	Create(ctx context.Context, item *Menu) error
	Update(ctx context.Context, item *Menu) error
	Delete(ctx context.Context, id string) error
	UpdateParentPath(ctx context.Context, id, parentPath string) error
	UpdateStatusByParentPath(ctx context.Context, parentPath, status string) error
}
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
}
func (a *MenuResource) TableName() string
type MenuResourceForm struct {
}
func (a *MenuResourceForm) FillTo(menuResource *MenuResource) error
func (a *MenuResourceForm) Validate() error
type MenuResourceQueryOptions struct {
	common.QueryOptions
}
type MenuResourceQueryParam struct {
	common.PaginationParam
	MenuID  string   `form:"-"` // From Menu.ID
	MenuIDs []string `form:"-"` // From Menu.ID
}
type MenuResourceQueryResult struct {
	Data       MenuResources
	PageResult *common.PaginationResult
}
type MenuResourceRepository interface {
	Query(ctx context.Context, params MenuResourceQueryParam, opts ...MenuResourceQueryOptions) (*MenuResourceQueryResult, error)
	Get(ctx context.Context, id string, opts ...MenuResourceQueryOptions) (*MenuResource, error)
	Exists(ctx context.Context, id string) (bool, error)
	ExistsMethodPathByMenuID(ctx context.Context, method, path, menuID string) (bool, error)
	Create(ctx context.Context, item *MenuResource) error
	Update(ctx context.Context, item *MenuResource) error
	Delete(ctx context.Context, id string) error
	DeleteByMenuID(ctx context.Context, menuID string) error
}
type MenuResources []*MenuResource
type MenuUsecase struct {
	// contains filtered or unexported fields
}

func NewMenuUsecase

func NewMenuUsecase(
	cache cachex.Cache,
	trans *common.Trans,
	menuRepository MenuRepository,
	menuResourceRepository MenuResourceRepository,
	roleMenuRepository RoleMenuRepository,
	conf *conf.ServerConf,
) *MenuUsecase

NewMenuUsecase initializes a new MenuUsecase with the provided dependencies.

cache: Cache interface for caching. trans: Trans pointer for translations. menuRepository: MenuRepository interface for menu operations. menuResourceRepository: MenuResourceRepository interface for menu resource operations. roleMenuRepository: RoleMenuRepository interface for role menu operations. conf: ServerConf pointer for server configuration. Returns a pointer to the initialized MenuUsecase.

func (a *MenuUsecase) Create(ctx context.Context, formItem *MenuForm) (*Menu, error)

Create a new menu in the data access object.

func (a *MenuUsecase) CreateInBatchByParent(ctx context.Context, items Menus, parent *Menu) error

CreateInBatchByParent creates multiple menu items in batch under a parent menu.

ctx: the context for the operation. items: the list of menu items to create. parent: the parent menu under which the items will be created. error: an error if any occurred during the operation.

func (a *MenuUsecase) Delete(ctx context.Context, id string) error

Delete the specified menu from the data access object.

func (a *MenuUsecase) Get(ctx context.Context, id string) (*Menu, error)

Get the specified menu from the data access object.

func (a *MenuUsecase) Query(ctx context.Context, params MenuQueryParam) (*MenuQueryResult, error)

Query menus from the data access object based on the provided parameters and options.

func (a *MenuUsecase) Update(ctx context.Context, id string, formItem *MenuForm) error

Update the specified menu in the data access object.

type Menus []*Menu
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 NodeInstanceCost

type NodeInstanceCost struct {
	RpsQuota         int
	GoroutineQuota   int
	RpsCost          int
	GoroutineCost    int
	RunningTaskCount int
	UnExist          bool
	// contains filtered or unexported fields
}

stress

type NodeListResult

type NodeListResult struct {
	Data []*NodeResultItem `json:"data"`
}

node

type NodeQuery

type NodeQuery struct {
	Addr string `form:"addr"`
}

node

type NodeQueryResult

type NodeQueryResult struct {
	Data []*repo.NodeState `json:"data"`
}

node

type NodeResultItem

type NodeResultItem struct {
	Addr             string `json:"addr"`
	RpsQuota         int    `json:"rps_quota"`
	GoroutineQuota   int    `json:"goroutine_quota"`
	RpsCost          int    `json:"rps_cost"`
	GoroutineCost    int    `json:"goroutine_cost"`
	RunningTaskCount int    `json:"running_task_count"`
}

node

type NodeUsecase

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

func NewNodeUsecase

func NewNodeUsecase(nodeRepository repo.NodeRepository, discovery registry.Discovery) *NodeUsecase

NewNodeUsecase creates a new NodeUsecase.

Parameters:

nodeRepository: repo.NodeRepository
discovery: registry.Discovery

Return type: *NodeUsecase

func (*NodeUsecase) QueryAllNodes

func (s *NodeUsecase) QueryAllNodes(ctx context.Context) (*NodeListResult, error)

QueryAllNodes retrieves all nodes using the provided context. It returns a NodeListResult pointer and an error. return rps、goroutine cost/total, status and node executing task count

func (*NodeUsecase) QueryNodes

func (s *NodeUsecase) QueryNodes(ctx context.Context, nodeQuery *NodeQuery) (*NodeQueryResult, error)

QueryNodes retrieves all nodes using the provided context. return node cpu/mem in graph

func (*NodeUsecase) UpdateNodeQuota

func (s *NodeUsecase) UpdateNodeQuota(ctx context.Context, updateNodeForm *UpdateNodeForm) (any, error)

UpdateNodeQuota updates the quota for a node.

ctx: the context for the operation. item: the form containing the updated node information. Returns two empty interfaces.

type Plan

type Plan struct {
	PlanId           uint64 `json:"-"`
	PlanName         string `json:"plan_name"`
	StartTime        int64  `json:"start_time"` // todo if StartTime > 0 then use scheduleTask
	StressTime       int    `json:"stress_time" binding:"required,min=1"`
	StressType       int    `json:"stress_type" binding:"required,min=1,max=2"`
	StressMode       int    `json:"stress_mode" binding:"required,min=1,max=2"`
	UserId           string `json:"user_id"`
	Tasks            []Task `json:"tasks"`
	StepIntervalTime int    `json:"step_interval_time"`
	IntervalLen      int    `json:"-"`
}

stress

type PlanQueryResult

type PlanQueryResult struct {
	Data       []*PlanRecordResultItem
	PageResult *common.PaginationResult
}

record

type PlanRecordQuery

type PlanRecordQuery struct {
	common.PaginationParam
	PlanId    uint64 `form:"plan_id"`
	PlanName  string `form:"plan_name"`
	StartTime int64  `form:"start_time"`
	EndTime   int64  `form:"end_time"`
}

stress

type PlanRecordResultItem

type PlanRecordResultItem struct {
	PlanId             string  `json:"plan_id"`
	UserId             string  `json:"user_id"`
	StartTime          int64   `json:"start_time"`
	StressTime         int     `json:"stress_time"`
	StressType         int     `json:"stress_type"`
	StressMode         int     `json:"stress_mode"`
	Status             int     `json:"status"`
	StressProgress     float64 `json:"stress_progress"`
	OverviewMetricsUrl string  `json:"overview_metrics_url"`
	PlanName           string  `json:"plan_name"`
	CreateTime         int64   `json:"create_time"`
	UpdateTime         int64   `json:"update_time"`
}

record

type Restart

type Restart struct {
	PlanId uint64
	UserId string
}

stress

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
}

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
}

func (*RoleForm) FillTo

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

func (*RoleForm) Validate

func (a *RoleForm) Validate() error

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
}

func (*RoleMenu) TableName

func (a *RoleMenu) TableName() string

type RoleMenuForm

type RoleMenuForm struct {
}

func (*RoleMenuForm) FillTo

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

func (*RoleMenuForm) Validate

func (a *RoleMenuForm) Validate() error

type RoleMenuQueryOptions

type RoleMenuQueryOptions struct {
	common.QueryOptions
}

type RoleMenuQueryParam

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

type RoleMenuQueryResult

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

type RoleMenuRepository

type RoleMenuRepository interface {
	Query(ctx context.Context, params RoleMenuQueryParam, opts ...RoleMenuQueryOptions) (*RoleMenuQueryResult, error)
	Get(ctx context.Context, id string, opts ...RoleMenuQueryOptions) (*RoleMenu, error)
	Exists(ctx context.Context, id string) (bool, error)
	Create(ctx context.Context, item *RoleMenu) error
	Update(ctx context.Context, item *RoleMenu) error
	Delete(ctx context.Context, id string) error
	DeleteByRoleID(ctx context.Context, roleID string) error
	DeleteByMenuID(ctx context.Context, menuID string) error
}

type RoleMenus

type RoleMenus []*RoleMenu

type RoleQueryOptions

type RoleQueryOptions struct {
	common.QueryOptions
}

type RoleQueryParam

type RoleQueryParam struct {
	common.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
}

type RoleQueryResult

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

type RoleRepository

type RoleRepository interface {
	Query(ctx context.Context, params RoleQueryParam, opts ...RoleQueryOptions) (*RoleQueryResult, error)
	Get(ctx context.Context, id string, opts ...RoleQueryOptions) (*Role, error)
	Exists(ctx context.Context, id string) (bool, error)
	ExistsCode(ctx context.Context, code string) (bool, error)
	Create(ctx context.Context, item *Role) error
	Update(ctx context.Context, item *Role) error
	Delete(ctx context.Context, id string) error
}

type RoleUsecase

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

func NewRoleUsecase

func NewRoleUsecase(
	cache cachex.Cache,
	trans *common.Trans,
	roleRepository RoleRepository,
	roleMenuRepository RoleMenuRepository,
	userRoleRepository UserRoleRepository,
) *RoleUsecase

func (*RoleUsecase) Create

func (a *RoleUsecase) Create(ctx context.Context, formItem *RoleForm) (*Role, error)

Create a new role in the data access object.

func (*RoleUsecase) Delete

func (a *RoleUsecase) Delete(ctx context.Context, id string) error

Delete the specified role from the data access object.

func (*RoleUsecase) Get

func (a *RoleUsecase) Get(ctx context.Context, id string) (*Role, error)

Get the specified role from the data access object.

func (*RoleUsecase) Query

func (a *RoleUsecase) Query(ctx context.Context, params RoleQueryParam) (*RoleQueryResult, error)

Query roles from the data access object based on the provided parameters and options.

func (*RoleUsecase) Update

func (a *RoleUsecase) Update(ctx context.Context, id string, formItem *RoleForm) error

Update the specified role in the data access object.

type Roles

type Roles []*Role

type ScheduledTask

type ScheduledTask struct {
	Task Task `json:"task"`
}

type ScheduledTaskRepository

type ScheduledTaskRepository interface {
	AddTask(ctx context.Context, ttl int64, scheduledTask *ScheduledTask) error
	WatchTask(ctx context.Context, execute func(task *ScheduledTask) bool)
}

type Stop

type Stop struct {
	PlanId string `json:"plan_id"`
	UserId string `json:"user_id"`
}

stress

type StressUsecase

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

func NewStressUsecase

func NewStressUsecase(recordRepository repo.RecordRepository, nodeRepository repo.NodeRepository,
	queRepository repo.QueRepository, discovery registry.Discovery, conf *conf.ServerConf) *StressUsecase

NewStressUsecase new stress usecase

func (*StressUsecase) QueryPlanAndTaskRecords

func (s *StressUsecase) QueryPlanAndTaskRecords(ctx context.Context, userId string, query TaskRecordQuery) (*Plan, error)

QueryPlanAndTaskRecords query plan and task record to copy stress plan task

func (*StressUsecase) QueryPlanTaskRecords

func (s *StressUsecase) QueryPlanTaskRecords(ctx context.Context, userId string, query TaskRecordQuery) (*TaskResult, error)

func (*StressUsecase) QueryUserRecords

func (s *StressUsecase) QueryUserRecords(ctx context.Context, userId string, query PlanRecordQuery) (*PlanQueryResult, error)

func (*StressUsecase) RestartStress

func (s *StressUsecase) RestartStress(ctx context.Context, restart *Restart) error

func (*StressUsecase) StartStress

func (s *StressUsecase) StartStress(ctx context.Context, in *Plan) error

StartStress starts the stress use case.

ctx: context.Context, in: *Plan error

func (*StressUsecase) Stop

func (s *StressUsecase) Stop(ctx context.Context, planId uint64, task *repo.TaskRecord)

Stop stops the task execution on the specified nodes.

Parameters: - ctx: the context for the request. - planId: the ID of the plan to stop. - task: the task record containing information about the nodes.

func (*StressUsecase) StopStress

func (s *StressUsecase) StopStress(ctx context.Context, b *Stop) error

StopStress stops stress for a given plan ID by stopping all associated tasks.

ctx context.Context, b *Stop error

type Summary

type Summary struct {
	Num    int
	TaskId uint64
	Rps    float64

	AvgTotal      int64
	Fastest       int64
	Slowest       int64
	Average       float64
	ErrorCount    int64
	ErrorRate     string
	SizeTotal     int64
	NumRes        int64
	TotalCostTime float64

	Lat90  int `json:"lat_90"`
	Lat95  int `json:"lat_95"`
	Lat99  int `json:"lat_99"`
	Lat999 int `json:"lat_999"`

	TimeBuckets         []int64 `json:"-"`
	StatusCodeDist      map[int]int64
	Histogram           []Bucket
	LatencyDistribution []LatencyDistribution
	ErrorDist           map[string]int64
	BodyCheckResultMap  map[string]int64
}

record

type Task

type Task struct {
	PlanId           uint64 `json:"-"`
	TaskId           uint64 `json:"-"`
	StressTime       int    `json:"-"`
	StressType       int    `json:"-"`
	StressMode       int    `json:"-"`
	StepIntervalTime int    `json:"-"`
	TaskName         string `json:"task_name" binding:"required"`
	Num              int    `json:"num" binding:"required,min=1"`
	MaxNum           int    `json:"max_num"`
	StepNum          int    `json:"step_num"`
	MaxConnections   int    `json:"max_connections" binding:"min=1"`
	Url              string `json:"url" binding:"required"`
	Method           string `json:"method" binding:"required,oneof=GET POST PUT DELETE"`
	Timeout          int    `json:"timeout" binding:"min=1,max=5000"`

	QueryEntry          []Entry           `json:"query"`
	HeaderEntry         []Entry           `json:"header"`
	Query               map[string]string `json:"-"`
	Headers             map[string]string `json:"-"`
	Body                string            `json:"body"`
	DynamicParamScript  string            `json:"dynamic_param_script"`
	ResponseCheckScript string            `json:"response_check_script"`

	DisableCompression bool `json:"-"`
	DisableKeepAlive   bool `json:"-"`
	DisableRedirects   bool `json:"-"`
	H2                 bool `json:"-"`

	Options []string `json:"options"`

	Proxy string `json:"proxy"`

	DynamicParams []DynamicParam `json:"-"`
	// contains filtered or unexported fields
}

stress

type TaskRecordQuery

type TaskRecordQuery struct {
	PlanId string `form:"plan_id"`
}

stress

type TaskResult

type TaskResult struct {
	Data []*TaskResultItem `json:"data"`
}

record

type TaskResultItem

type TaskResultItem struct {
	TaskId              string    `json:"task_id"`
	TaskName            string    `json:"task_name"`
	TaskStatus          int       `json:"task_status"`
	PlanId              string    `json:"plan_id"`
	Url                 string    `json:"url"`
	StressType          int       `json:"stress_type"`
	StressMode          int       `json:"stress_mode"`
	Num                 int       `json:"num" binding:"required,min=1"`
	MaxNum              int       `json:"max_num"`
	StepNum             int       `json:"step_num"`
	Timeout             int       `json:"timeout" `
	MaxConnections      int       `json:"max_connections"`
	ProtocolType        int       `json:"protocol_type"`
	Method              string    `json:"method"`
	QueryEntry          []Entry   `json:"query"`
	HeaderEntry         []Entry   `json:"header"`
	Body                *JsonBody `json:"body"`
	DynamicParamScript  string    `json:"dynamic_param_script"`
	ResponseCheckScript string    `json:"response_check_script"`

	DisableCompression int8   `json:"disable_compression"`
	DisableKeepAlive   int8   `json:"disable_keep_alive"`
	DisableRedirects   int8   `json:"disable_redirects"`
	H2                 int8   `json:"h_2"`
	Proxy              string `json:"proxy"`

	MaxBodySize int64 `json:"max_body_size"`

	Nodes string `json:"nodes"`

	MetricsUrl string `json:"metrics_url"`

	Reports []*Summary `json:"reports"`

	CreateTime int64 `json:"create_time"`
	UpdateTime int64 `json:"update_time"`
}

record

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
}

login

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

login

type UpdateNodeForm

type UpdateNodeForm struct {
	Addr           string `json:"addr"`
	RpsQuota       int    `json:"rps_quota"`
	GoroutineQuota int    `json:"goroutine_quota"`
}

node

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
}

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
}

func (*UserForm) FillTo

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

func (*UserForm) Validate

func (a *UserForm) Validate() error

type UserQueryOptions

type UserQueryOptions struct {
	common.QueryOptions
}

type UserQueryParam

type UserQueryParam struct {
	common.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)
}

type UserQueryResult

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

type UserRepository

type UserRepository interface {
	Query(ctx context.Context, params UserQueryParam, opts ...UserQueryOptions) (*UserQueryResult, error)
	Get(ctx context.Context, id string, opts ...UserQueryOptions) (*User, error)
	GetByUsername(ctx context.Context, username string, opts ...UserQueryOptions) (*User, error)
	Exists(ctx context.Context, id string) (bool, error)
	ExistsUsername(ctx context.Context, username string) (bool, error)
	Create(ctx context.Context, item *User) error
	Update(ctx context.Context, item *User, selectFields ...string) error
	Delete(ctx context.Context, id string) error
	UpdatePasswordByID(ctx context.Context, id string, password string) error
}

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
}

func (*UserRole) TableName

func (a *UserRole) TableName() string

type UserRoleForm

type UserRoleForm struct {
}

func (*UserRoleForm) FillTo

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

func (*UserRoleForm) Validate

func (a *UserRoleForm) Validate() error

type UserRoleQueryOptions

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

type UserRoleQueryParam

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

type UserRoleQueryResult

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

type UserRoleRepository

type UserRoleRepository interface {
	Query(ctx context.Context, param UserRoleQueryParam, options ...UserRoleQueryOptions) (*UserRoleQueryResult, error)
	Get(ctx context.Context, id string, opts ...UserRoleQueryOptions) (*UserRole, error)
	Exists(ctx context.Context, id string) (bool, error)
	Create(ctx context.Context, item *UserRole) error
	Update(ctx context.Context, item *UserRole) error
	Delete(ctx context.Context, id string) error
	DeleteByUserID(ctx context.Context, userID string) error
	DeleteByRoleID(ctx context.Context, roleID string) error
}

type UserRoles

type UserRoles []*UserRole

func (UserRoles) ToRoleIDs

func (a UserRoles) ToRoleIDs() []string

func (UserRoles) ToUserIDMap

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

type UserUsecase

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

func NewUserUsecase

func NewUserUsecase(
	cache cachex.Cache,
	trans *common.Trans,
	userRepository UserRepository,
	userRoleRepository UserRoleRepository,
	conf *conf.ServerConf,
) *UserUsecase

func (*UserUsecase) Create

func (a *UserUsecase) Create(ctx context.Context, formItem *UserForm) (*User, error)

Create a new user in the data access object.

func (*UserUsecase) Delete

func (a *UserUsecase) Delete(ctx context.Context, id string) error

Delete the specified user from the data access object.

func (*UserUsecase) Get

func (a *UserUsecase) Get(ctx context.Context, id string) (*User, error)

Get the specified user from the data access object.

func (*UserUsecase) GetRoleIDs

func (a *UserUsecase) GetRoleIDs(ctx context.Context, id string) ([]string, error)

func (*UserUsecase) Query

func (a *UserUsecase) Query(ctx context.Context, params UserQueryParam) (*UserQueryResult, error)

Query users from the data access object based on the provided parameters and options.

func (*UserUsecase) ResetPassword

func (a *UserUsecase) ResetPassword(ctx context.Context, id string) error

func (*UserUsecase) Update

func (a *UserUsecase) Update(ctx context.Context, id string, formItem *UserForm) error

Update the specified user in the data access object.

type Users

type Users []*User

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