mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-09-29 13:22:14 +08:00
add event
This commit is contained in:
@@ -9,7 +9,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
@@ -86,12 +86,12 @@ func initProcess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initJwtSecret() {
|
func initJwtSecret() {
|
||||||
if secret, err := repository.ConfigRepository.GetConfigValue(constants.SECRET_KEY); err == nil {
|
if secret, err := repository.ConfigRepository.GetConfigValue(eum.SecretKey); err == nil {
|
||||||
utils.SetSecret([]byte(secret))
|
utils.SetSecret([]byte(secret))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
secret := utils.RandString(32)
|
secret := utils.RandString(32)
|
||||||
repository.ConfigRepository.SetConfigValue(constants.SECRET_KEY, secret)
|
repository.ConfigRepository.SetConfigValue(eum.SecretKey, secret)
|
||||||
utils.SetSecret([]byte(secret))
|
utils.SetSecret([]byte(secret))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3,28 +3,28 @@ package api
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getRole(ctx *gin.Context) constants.Role {
|
func getRole(ctx *gin.Context) eum.Role {
|
||||||
if v, ok := ctx.Get(constants.CTXFLG_ROLE); ok {
|
if v, ok := ctx.Get(eum.CtxRole); ok {
|
||||||
return v.(constants.Role)
|
return v.(eum.Role)
|
||||||
}
|
}
|
||||||
return constants.ROLE_GUEST
|
return eum.RoleGuest
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUserName(ctx *gin.Context) string {
|
func getUserName(ctx *gin.Context) string {
|
||||||
return ctx.GetString(constants.CTXFLG_USER_NAME)
|
return ctx.GetString(eum.CtxUserName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isAdmin(ctx *gin.Context) bool {
|
func isAdmin(ctx *gin.Context) bool {
|
||||||
return getRole(ctx) <= constants.ROLE_ADMIN
|
return getRole(ctx) <= eum.RoleAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasOprPermission(ctx *gin.Context, uuid int, op constants.OprPermission) bool {
|
func hasOprPermission(ctx *gin.Context, uuid int, op eum.OprPermission) bool {
|
||||||
return isAdmin(ctx) || reflect.ValueOf(repository.PermissionRepository.GetPermission(getUserName(ctx), uuid)).FieldByName(string(op)).Bool()
|
return isAdmin(ctx) || reflect.ValueOf(repository.PermissionRepository.GetPermission(getUserName(ctx), uuid)).FieldByName(string(op)).Bool()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
@@ -20,7 +20,7 @@ func (a *logApi) GetLog(ctx *gin.Context, req model.GetLogReq) any {
|
|||||||
if isAdmin(ctx) {
|
if isAdmin(ctx) {
|
||||||
return logic.LogLogicImpl.Search(req, req.FilterName...)
|
return logic.LogLogicImpl.Search(req, req.FilterName...)
|
||||||
} else {
|
} else {
|
||||||
processNameList := repository.PermissionRepository.GetProcessNameByPermission(getUserName(ctx), constants.OPERATION_LOG)
|
processNameList := repository.PermissionRepository.GetProcessNameByPermission(getUserName(ctx), eum.OperationLog)
|
||||||
filterName := slices.DeleteFunc(req.FilterName, func(s string) bool {
|
filterName := slices.DeleteFunc(req.FilterName, func(s string) bool {
|
||||||
return !slices.Contains(processNameList, s)
|
return !slices.Contains(processNameList, s)
|
||||||
})
|
})
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -35,10 +35,10 @@ func (u *userApi) LoginHandler(ctx *gin.Context, req model.LoginHandlerReq) any
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *userApi) CreateUser(ctx *gin.Context, req model.User) (err error) {
|
func (u *userApi) CreateUser(ctx *gin.Context, req model.User) (err error) {
|
||||||
if req.Role == constants.ROLE_ROOT {
|
if req.Role == eum.RoleRoot {
|
||||||
return errors.New("creation of root accounts is forbidden")
|
return errors.New("creation of root accounts is forbidden")
|
||||||
}
|
}
|
||||||
if req.Account == constants.CONSOLE {
|
if req.Account == eum.Console {
|
||||||
return errors.New("operation failed")
|
return errors.New("operation failed")
|
||||||
}
|
}
|
||||||
if len(req.Password) < config.CF.UserPassWordMinLength {
|
if len(req.Password) < config.CF.UserPassWordMinLength {
|
||||||
@@ -50,7 +50,7 @@ func (u *userApi) CreateUser(ctx *gin.Context, req model.User) (err error) {
|
|||||||
|
|
||||||
func (u *userApi) ChangePassword(ctx *gin.Context, req model.User) (err error) {
|
func (u *userApi) ChangePassword(ctx *gin.Context, req model.User) (err error) {
|
||||||
reqUser := getUserName(ctx)
|
reqUser := getUserName(ctx)
|
||||||
if getRole(ctx) != constants.ROLE_ROOT && req.Account != "" {
|
if getRole(ctx) != eum.RoleRoot && req.Account != "" {
|
||||||
return errors.New("invalid parameters")
|
return errors.New("invalid parameters")
|
||||||
}
|
}
|
||||||
var userName string
|
var userName string
|
||||||
@@ -84,7 +84,7 @@ func (u *userApi) checkLoginInfo(account, password string) bool {
|
|||||||
repository.UserRepository.CreateUser(model.User{
|
repository.UserRepository.CreateUser(model.User{
|
||||||
Account: "root",
|
Account: "root",
|
||||||
Password: DEFAULT_ROOT_PASSWORD,
|
Password: DEFAULT_ROOT_PASSWORD,
|
||||||
Role: constants.ROLE_ROOT,
|
Role: eum.RoleRoot,
|
||||||
})
|
})
|
||||||
return password == DEFAULT_ROOT_PASSWORD
|
return password == DEFAULT_ROOT_PASSWORD
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
@@ -76,7 +76,7 @@ func (w *wsApi) WebsocketHandle(ctx *gin.Context, req model.WebsocketHandleReq)
|
|||||||
proc.ReadCache(wci)
|
proc.ReadCache(wci)
|
||||||
if proc.State.State == 1 {
|
if proc.State.State == 1 {
|
||||||
proc.SetTerminalSize(req.Cols, req.Rows)
|
proc.SetTerminalSize(req.Cols, req.Rows)
|
||||||
w.startWsConnect(wci, cancel, proc, hasOprPermission(ctx, req.Uuid, constants.OPERATION_TERMINAL_WRITE))
|
w.startWsConnect(wci, cancel, proc, hasOprPermission(ctx, req.Uuid, eum.OperationTerminalWrite))
|
||||||
proc.AddConn(reqUser, wci)
|
proc.AddConn(reqUser, wci)
|
||||||
defer proc.DeleteConn(reqUser)
|
defer proc.DeleteConn(reqUser)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
const (
|
|
||||||
SECRET_KEY = "secret"
|
|
||||||
CONSOLE = "console"
|
|
||||||
)
|
|
@@ -1,7 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
const (
|
|
||||||
CTXFLG_USER_NAME = "user"
|
|
||||||
CTXFLG_ROLE = "role"
|
|
||||||
CTXFLG_ERR = "err"
|
|
||||||
)
|
|
@@ -1,11 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
type OprPermission string
|
|
||||||
|
|
||||||
const (
|
|
||||||
OPERATION_START OprPermission = "Start"
|
|
||||||
OPERATION_STOP OprPermission = "Stop"
|
|
||||||
OPERATION_TERMINAL OprPermission = "Terminal"
|
|
||||||
OPERATION_TERMINAL_WRITE OprPermission = "Write"
|
|
||||||
OPERATION_LOG OprPermission = "Log"
|
|
||||||
)
|
|
@@ -1,16 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
type TerminalType string
|
|
||||||
|
|
||||||
const (
|
|
||||||
TERMINAL_PTY TerminalType = "pty"
|
|
||||||
TERMINAL_STD TerminalType = "std"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ProcessState int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
PROCESS_STOP ProcessState = iota
|
|
||||||
PROCESS_START
|
|
||||||
PROCESS_WARNNING
|
|
||||||
)
|
|
@@ -1,10 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
type Role int
|
|
||||||
|
|
||||||
const (
|
|
||||||
ROLE_ROOT Role = iota
|
|
||||||
ROLE_ADMIN
|
|
||||||
ROLE_USER
|
|
||||||
ROLE_GUEST
|
|
||||||
)
|
|
@@ -1,19 +0,0 @@
|
|||||||
package constants
|
|
||||||
|
|
||||||
type Condition int
|
|
||||||
|
|
||||||
const (
|
|
||||||
RUNNING Condition = iota
|
|
||||||
NOT_RUNNING
|
|
||||||
EXCEPTION
|
|
||||||
PASS
|
|
||||||
)
|
|
||||||
|
|
||||||
type TaskOperation int
|
|
||||||
|
|
||||||
const (
|
|
||||||
TASK_START TaskOperation = iota
|
|
||||||
TASK_STOP
|
|
||||||
TASK_START_WAIT_DONE
|
|
||||||
TASK_STOP_WAIT_DONE
|
|
||||||
)
|
|
6
internal/app/eum/consts.go
Normal file
6
internal/app/eum/consts.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
const (
|
||||||
|
SecretKey = "secret"
|
||||||
|
Console = "console"
|
||||||
|
)
|
11
internal/app/eum/event.go
Normal file
11
internal/app/eum/event.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
type EventType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
EventProcessStart EventType = "ProcessStart"
|
||||||
|
EventProcessStop EventType = "ProcessStop"
|
||||||
|
EventProcessWarning EventType = "ProcessWarning"
|
||||||
|
EventTaskStart EventType = "TaskStart"
|
||||||
|
EventTaskStop EventType = "TaskStop"
|
||||||
|
)
|
6
internal/app/eum/gin.go
Normal file
6
internal/app/eum/gin.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
const (
|
||||||
|
CtxUserName = "user"
|
||||||
|
CtxRole = "role"
|
||||||
|
)
|
11
internal/app/eum/permission.go
Normal file
11
internal/app/eum/permission.go
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
type OprPermission string
|
||||||
|
|
||||||
|
const (
|
||||||
|
OperationStart OprPermission = "Start"
|
||||||
|
OperationStop OprPermission = "Stop"
|
||||||
|
OperationTerminal OprPermission = "Terminal"
|
||||||
|
OperationTerminalWrite OprPermission = "Write"
|
||||||
|
OperationLog OprPermission = "Log"
|
||||||
|
)
|
16
internal/app/eum/process.go
Normal file
16
internal/app/eum/process.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
type TerminalType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
TerminalPty TerminalType = "pty"
|
||||||
|
TerminalStd TerminalType = "std"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProcessState int32
|
||||||
|
|
||||||
|
const (
|
||||||
|
ProcessStateStop ProcessState = iota
|
||||||
|
ProcessStateStart
|
||||||
|
ProcessStateWarnning
|
||||||
|
)
|
10
internal/app/eum/role.go
Normal file
10
internal/app/eum/role.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
type Role int
|
||||||
|
|
||||||
|
const (
|
||||||
|
RoleRoot Role = iota
|
||||||
|
RoleAdmin
|
||||||
|
RoleUser
|
||||||
|
RoleGuest
|
||||||
|
)
|
21
internal/app/eum/task.go
Normal file
21
internal/app/eum/task.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package eum
|
||||||
|
|
||||||
|
type Condition int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TaskCondRunning Condition = iota
|
||||||
|
TaskCondNotRunning
|
||||||
|
TaskCondException
|
||||||
|
TaskCondPass
|
||||||
|
)
|
||||||
|
|
||||||
|
type TaskOperation int
|
||||||
|
|
||||||
|
const (
|
||||||
|
TaskStart TaskOperation = iota
|
||||||
|
TaskStop
|
||||||
|
TaskStartWaitDone
|
||||||
|
TaskStopWaitDone
|
||||||
|
)
|
||||||
|
|
||||||
|
type CtxTaskTraceId struct{}
|
30
internal/app/logic/event.go
Normal file
30
internal/app/logic/event.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package logic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type eventLogic struct{}
|
||||||
|
|
||||||
|
var EventLogic = new(eventLogic)
|
||||||
|
|
||||||
|
func (e *eventLogic) Create(name string, eventType eum.EventType, additionalKv ...any) error {
|
||||||
|
if len(additionalKv)%2 != 0 {
|
||||||
|
log.Logger.Errorw("参数长度错误", "args", additionalKv)
|
||||||
|
}
|
||||||
|
data := model.Event{
|
||||||
|
Name: name,
|
||||||
|
CreatedTime: time.Now(),
|
||||||
|
Type: eventType,
|
||||||
|
}
|
||||||
|
m := map[any]any{}
|
||||||
|
for i := range len(additionalKv) / 2 {
|
||||||
|
m[additionalKv[2*i]] = additionalKv[2*i+1]
|
||||||
|
}
|
||||||
|
return repository.EventRepository.Create(data)
|
||||||
|
}
|
@@ -10,7 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
@@ -27,7 +27,7 @@ type Process interface {
|
|||||||
doOnInit()
|
doOnInit()
|
||||||
doOnKilled()
|
doOnKilled()
|
||||||
Start() error
|
Start() error
|
||||||
Type() constants.TerminalType
|
Type() eum.TerminalType
|
||||||
SetTerminalSize(int, int)
|
SetTerminalSize(int, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ type ProcessBase struct {
|
|||||||
State struct {
|
State struct {
|
||||||
startTime time.Time
|
startTime time.Time
|
||||||
Info string
|
Info string
|
||||||
State constants.ProcessState //0 为未运行,1为运作中,2为异常状态
|
State eum.ProcessState //0 为未运行,1为运作中,2为异常状态
|
||||||
stateLock sync.Mutex
|
stateLock sync.Mutex
|
||||||
restartTimes int
|
restartTimes int
|
||||||
manualStopFlag bool
|
manualStopFlag bool
|
||||||
@@ -93,7 +93,7 @@ func (p *ProcessBase) watchDog() {
|
|||||||
}
|
}
|
||||||
close(p.StopChan)
|
close(p.StopChan)
|
||||||
p.doOnKilled()
|
p.doOnKilled()
|
||||||
p.SetState(constants.PROCESS_STOP)
|
p.SetState(eum.ProcessStateStop)
|
||||||
if state.ExitCode() != 0 {
|
if state.ExitCode() != 0 {
|
||||||
log.Logger.Infow("进程停止", "进程名称", p.Name, "exitCode", state.ExitCode(), "进程类型", p.Type())
|
log.Logger.Infow("进程停止", "进程名称", p.Name, "exitCode", state.ExitCode(), "进程类型", p.Type())
|
||||||
p.push(fmt.Sprintf("进程停止,退出码 %d", state.ExitCode()))
|
p.push(fmt.Sprintf("进程停止,退出码 %d", state.ExitCode()))
|
||||||
@@ -117,7 +117,7 @@ func (p *ProcessBase) watchDog() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Logger.Warnw("重启次数达到上限", "name", p.Name, "limit", config.CF.ProcessRestartsLimit)
|
log.Logger.Warnw("重启次数达到上限", "name", p.Name, "limit", config.CF.ProcessRestartsLimit)
|
||||||
p.SetState(constants.PROCESS_WARNNING)
|
p.SetState(eum.ProcessStateWarnning)
|
||||||
p.State.Info = "重启次数异常"
|
p.State.Info = "重启次数异常"
|
||||||
p.push("进程重启次数达到上限")
|
p.push("进程重启次数达到上限")
|
||||||
}
|
}
|
||||||
@@ -139,7 +139,7 @@ func (p *ProcessBase) pInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fn 函数执行成功的情况下对state赋值
|
// fn 函数执行成功的情况下对state赋值
|
||||||
func (p *ProcessBase) SetState(state constants.ProcessState, fn ...func() bool) bool {
|
func (p *ProcessBase) SetState(state eum.ProcessState, fn ...func() bool) bool {
|
||||||
p.State.stateLock.Lock()
|
p.State.stateLock.Lock()
|
||||||
defer p.State.stateLock.Unlock()
|
defer p.State.stateLock.Unlock()
|
||||||
for _, v := range fn {
|
for _, v := range fn {
|
||||||
@@ -149,10 +149,24 @@ func (p *ProcessBase) SetState(state constants.ProcessState, fn ...func() bool)
|
|||||||
}
|
}
|
||||||
p.State.State = state
|
p.State.State = state
|
||||||
middle.ProcessWaitCond.Trigger()
|
middle.ProcessWaitCond.Trigger()
|
||||||
|
p.createEvent(state)
|
||||||
go TaskLogic.RunTaskByTriggerEvent(p.Name, state)
|
go TaskLogic.RunTaskByTriggerEvent(p.Name, state)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *ProcessBase) createEvent(state eum.ProcessState) {
|
||||||
|
var eventType eum.EventType
|
||||||
|
switch state {
|
||||||
|
case eum.ProcessStateStart:
|
||||||
|
eventType = eum.EventProcessStart
|
||||||
|
case eum.ProcessStateStop:
|
||||||
|
eventType = eum.EventProcessStop
|
||||||
|
case eum.ProcessStateWarnning:
|
||||||
|
eventType = eum.EventProcessWarning
|
||||||
|
}
|
||||||
|
EventLogic.Create(p.Name, eventType, "")
|
||||||
|
}
|
||||||
|
|
||||||
func (p *ProcessBase) GetUserString() string {
|
func (p *ProcessBase) GetUserString() string {
|
||||||
return strings.Join(p.GetUserList(), ";")
|
return strings.Join(p.GetUserList(), ";")
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
@@ -76,7 +76,7 @@ func (p *processCtlLogic) KillAllProcess() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *processCtlLogic) KillAllProcessByUserName(userName string) {
|
func (p *processCtlLogic) KillAllProcessByUserName(userName string) {
|
||||||
stopPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, constants.OPERATION_STOP)
|
stopPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, eum.OperationStop)
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
p.processMap.Range(func(key, value any) bool {
|
p.processMap.Range(func(key, value any) bool {
|
||||||
process := value.(*ProcessBase)
|
process := value.(*ProcessBase)
|
||||||
@@ -183,7 +183,7 @@ func (p *processCtlLogic) ProcessInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *processCtlLogic) ProcesStartAllByUsername(userName string) {
|
func (p *processCtlLogic) ProcesStartAllByUsername(userName string) {
|
||||||
startPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, constants.OPERATION_START)
|
startPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, eum.OperationStart)
|
||||||
p.processMap.Range(func(key, value any) bool {
|
p.processMap.Range(func(key, value any) bool {
|
||||||
process := value.(*ProcessBase)
|
process := value.(*ProcessBase)
|
||||||
if !slices.Contains(startPermissionProcess, process.Name) {
|
if !slices.Contains(startPermissionProcess, process.Name) {
|
||||||
@@ -225,9 +225,9 @@ func (p *processCtlLogic) UpdateProcessConfig(config model.Process) error {
|
|||||||
|
|
||||||
func (p *processCtlLogic) NewProcess(config model.Process) (proc *ProcessBase, err error) {
|
func (p *processCtlLogic) NewProcess(config model.Process) (proc *ProcessBase, err error) {
|
||||||
switch config.TermType {
|
switch config.TermType {
|
||||||
case constants.TERMINAL_STD:
|
case eum.TerminalStd:
|
||||||
proc = NewProcessStd(config)
|
proc = NewProcessStd(config)
|
||||||
case constants.TERMINAL_PTY:
|
case eum.TerminalPty:
|
||||||
proc = NewProcessPty(config)
|
proc = NewProcessPty(config)
|
||||||
default:
|
default:
|
||||||
err = errors.New("终端类型错误")
|
err = errors.New("终端类型错误")
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -26,19 +26,19 @@ func (p *ProcessPty) doOnKilled() {
|
|||||||
p.pty.Close()
|
p.pty.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessPty) Type() constants.TerminalType {
|
func (p *ProcessPty) Type() eum.TerminalType {
|
||||||
return constants.TERMINAL_PTY
|
return eum.TerminalPty
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessPty) Start() (err error) {
|
func (p *ProcessPty) Start() (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Config.AutoRestart = false
|
p.Config.AutoRestart = false
|
||||||
p.SetState(constants.PROCESS_WARNNING)
|
p.SetState(eum.ProcessStateWarnning)
|
||||||
p.State.Info = "进程启动失败:" + err.Error()
|
p.State.Info = "进程启动失败:" + err.Error()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||||
return p.State.State != 1
|
return p.State.State != 1
|
||||||
}); !ok {
|
}); !ok {
|
||||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -24,19 +24,19 @@ func (p *ProcessPty) doOnKilled() {
|
|||||||
p.pty.Close()
|
p.pty.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessPty) Type() constants.TerminalType {
|
func (p *ProcessPty) Type() eum.TerminalType {
|
||||||
return constants.TERMINAL_PTY
|
return eum.TerminalPty
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessPty) Start() (err error) {
|
func (p *ProcessPty) Start() (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Config.AutoRestart = false
|
p.Config.AutoRestart = false
|
||||||
p.SetState(constants.PROCESS_WARNNING)
|
p.SetState(eum.ProcessStateWarnning)
|
||||||
p.State.Info = "进程启动失败:" + err.Error()
|
p.State.Info = "进程启动失败:" + err.Error()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||||
return p.State.State != 1
|
return p.State.State != 1
|
||||||
}); !ok {
|
}); !ok {
|
||||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/google/shlex"
|
"github.com/google/shlex"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -21,8 +21,8 @@ type ProcessStd struct {
|
|||||||
stdout *bufio.Scanner
|
stdout *bufio.Scanner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessStd) Type() constants.TerminalType {
|
func (p *ProcessStd) Type() eum.TerminalType {
|
||||||
return constants.TERMINAL_STD
|
return eum.TerminalStd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProcessStd) WriteBytes(input []byte) (err error) {
|
func (p *ProcessStd) WriteBytes(input []byte) (err error) {
|
||||||
@@ -41,11 +41,11 @@ func (p *ProcessStd) Start() (err error) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Config.AutoRestart = false
|
p.Config.AutoRestart = false
|
||||||
p.SetState(constants.PROCESS_WARNNING)
|
p.SetState(eum.ProcessStateWarnning)
|
||||||
p.State.Info = "进程启动失败:" + err.Error()
|
p.State.Info = "进程启动失败:" + err.Error()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||||
return p.State.State != 1
|
return p.State.State != 1
|
||||||
}); !ok {
|
}); !ok {
|
||||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||||
|
@@ -4,7 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/google/uuid"
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
@@ -35,6 +36,10 @@ func NewTaskJob(data model.Task) (*TaskJob, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TaskJob) Run(ctx context.Context) {
|
func (t *TaskJob) Run(ctx context.Context) {
|
||||||
|
if ctx.Value(eum.CtxTaskTraceId{}) == nil {
|
||||||
|
ctx = context.WithValue(ctx, eum.CtxTaskTraceId{}, uuid.NewString())
|
||||||
|
}
|
||||||
|
EventLogic.Create(t.TaskConfig.Name, eum.EventTaskStart, "traceId", ctx.Value(eum.CtxTaskTraceId{}))
|
||||||
t.Running = true
|
t.Running = true
|
||||||
middle.TaskWaitCond.Trigger()
|
middle.TaskWaitCond.Trigger()
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -43,7 +48,7 @@ func (t *TaskJob) Run(ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
var ok bool
|
var ok bool
|
||||||
// 判断条件是否满足
|
// 判断条件是否满足
|
||||||
if t.TaskConfig.Condition == constants.PASS {
|
if t.TaskConfig.Condition == eum.TaskCondPass {
|
||||||
ok = true
|
ok = true
|
||||||
} else {
|
} else {
|
||||||
proc, err := ProcessCtlLogic.GetProcess(t.TaskConfig.OperationTarget)
|
proc, err := ProcessCtlLogic.GetProcess(t.TaskConfig.OperationTarget)
|
||||||
@@ -91,6 +96,7 @@ func (t *TaskJob) Run(ctx context.Context) {
|
|||||||
} else {
|
} else {
|
||||||
log.Logger.Infow("任务流结束")
|
log.Logger.Infow("任务流结束")
|
||||||
}
|
}
|
||||||
|
EventLogic.Create(t.TaskConfig.Name, eum.EventProcessStop, "traceId", ctx.Value(eum.CtxTaskTraceId{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TaskJob) InitCronHandle() error {
|
func (t *TaskJob) InitCronHandle() error {
|
||||||
|
@@ -4,21 +4,21 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type conditionFunc func(data *model.Task, proc *ProcessBase) bool
|
type conditionFunc func(data *model.Task, proc *ProcessBase) bool
|
||||||
|
|
||||||
var conditionHandle = map[constants.Condition]conditionFunc{
|
var conditionHandle = map[eum.Condition]conditionFunc{
|
||||||
constants.RUNNING: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskCondRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
return proc.State.State == 1
|
return proc.State.State == 1
|
||||||
},
|
},
|
||||||
constants.NOT_RUNNING: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskCondNotRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
return proc.State.State != 1
|
return proc.State.State != 1
|
||||||
},
|
},
|
||||||
constants.EXCEPTION: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskCondException: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
return proc.State.State == 2
|
return proc.State.State == 2
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,8 @@ var conditionHandle = map[constants.Condition]conditionFunc{
|
|||||||
// 执行操作,返回结果是否成功
|
// 执行操作,返回结果是否成功
|
||||||
type operationFunc func(data *model.Task, proc *ProcessBase) bool
|
type operationFunc func(data *model.Task, proc *ProcessBase) bool
|
||||||
|
|
||||||
var OperationHandle = map[constants.TaskOperation]operationFunc{
|
var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||||
constants.TASK_START: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskStart: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
if proc.State.State == 1 {
|
if proc.State.State == 1 {
|
||||||
log.Logger.Debugw("进程已在运行")
|
log.Logger.Debugw("进程已在运行")
|
||||||
return false
|
return false
|
||||||
@@ -36,7 +36,7 @@ var OperationHandle = map[constants.TaskOperation]operationFunc{
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
constants.TASK_START_WAIT_DONE: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskStartWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
if proc.State.State == 1 {
|
if proc.State.State == 1 {
|
||||||
log.Logger.Debugw("进程已在运行")
|
log.Logger.Debugw("进程已在运行")
|
||||||
return false
|
return false
|
||||||
@@ -55,7 +55,7 @@ var OperationHandle = map[constants.TaskOperation]operationFunc{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
constants.TASK_STOP: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskStop: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
if proc.State.State != 1 {
|
if proc.State.State != 1 {
|
||||||
log.Logger.Debugw("进程未在运行")
|
log.Logger.Debugw("进程未在运行")
|
||||||
return false
|
return false
|
||||||
@@ -66,7 +66,7 @@ var OperationHandle = map[constants.TaskOperation]operationFunc{
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
|
|
||||||
constants.TASK_STOP_WAIT_DONE: func(data *model.Task, proc *ProcessBase) bool {
|
eum.TaskStopWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||||
if proc.State.State != 1 {
|
if proc.State.State != 1 {
|
||||||
log.Logger.Debugw("进程未在运行")
|
log.Logger.Debugw("进程未在运行")
|
||||||
return false
|
return false
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
@@ -154,7 +154,7 @@ func (t *taskLogic) RunTaskByKey(key string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *taskLogic) RunTaskByTriggerEvent(processName string, event constants.ProcessState) {
|
func (t *taskLogic) RunTaskByTriggerEvent(processName string, event eum.ProcessState) {
|
||||||
taskList := repository.TaskRepository.GetTriggerTask(processName, event)
|
taskList := repository.TaskRepository.GetTriggerTask(processName, event)
|
||||||
if len(taskList) == 0 {
|
if len(taskList) == 0 {
|
||||||
return
|
return
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ func Logger() gin.HandlerFunc {
|
|||||||
logKv = append(logKv, "Status", ctx.Writer.Status())
|
logKv = append(logKv, "Status", ctx.Writer.Status())
|
||||||
logKv = append(logKv, "Path", path)
|
logKv = append(logKv, "Path", path)
|
||||||
logKv = append(logKv, "耗时", fmt.Sprintf("%dms", time.Now().UnixMilli()-start.UnixMilli()))
|
logKv = append(logKv, "耗时", fmt.Sprintf("%dms", time.Now().UnixMilli()-start.UnixMilli()))
|
||||||
if user, ok := ctx.Get(constants.CTXFLG_USER_NAME); ok {
|
if user, ok := ctx.Get(eum.CtxUserName); ok {
|
||||||
logKv = append(logKv, "user", user)
|
logKv = append(logKv, "user", user)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
|
@@ -4,15 +4,15 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RolePermission(needPermission constants.Role) func(ctx *gin.Context) {
|
func RolePermission(needPermission eum.Role) func(ctx *gin.Context) {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
if v, ok := ctx.Get(constants.CTXFLG_ROLE); !ok || v.(constants.Role) > needPermission {
|
if v, ok := ctx.Get(eum.CtxRole); !ok || v.(eum.Role) > needPermission {
|
||||||
rErr(ctx, -1, "Insufficient permissions; please check your access rights!", nil)
|
rErr(ctx, -1, "Insufficient permissions; please check your access rights!", nil)
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
@@ -21,7 +21,7 @@ func RolePermission(needPermission constants.Role) func(ctx *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func OprPermission(op constants.OprPermission) func(ctx *gin.Context) {
|
func OprPermission(op eum.OprPermission) func(ctx *gin.Context) {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
uuid, err := strconv.Atoi(ctx.Query("uuid"))
|
uuid, err := strconv.Atoi(ctx.Query("uuid"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,11 +29,11 @@ func OprPermission(op constants.OprPermission) func(ctx *gin.Context) {
|
|||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if v, ok := ctx.Get(constants.CTXFLG_ROLE); !ok || v.(constants.Role) <= constants.ROLE_ADMIN {
|
if v, ok := ctx.Get(eum.CtxRole); !ok || v.(eum.Role) <= eum.RoleAdmin {
|
||||||
ctx.Next()
|
ctx.Next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !reflect.ValueOf(repository.PermissionRepository.GetPermission(ctx.GetString(constants.CTXFLG_USER_NAME), uuid)).FieldByName(string(op)).Bool() {
|
if !reflect.ValueOf(repository.PermissionRepository.GetPermission(ctx.GetString(eum.CtxUserName), uuid)).FieldByName(string(op)).Bool() {
|
||||||
rErr(ctx, -1, "Insufficient permissions; please check your access rights!", nil)
|
rErr(ctx, -1, "Insufficient permissions; please check your access rights!", nil)
|
||||||
ctx.Abort()
|
ctx.Abort()
|
||||||
return
|
return
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -58,8 +58,8 @@ func CheckToken() gin.HandlerFunc {
|
|||||||
if username, err := getUser(c); err != nil {
|
if username, err := getUser(c); err != nil {
|
||||||
rErr(c, -1, "无法获取user信息", err)
|
rErr(c, -1, "无法获取user信息", err)
|
||||||
} else {
|
} else {
|
||||||
c.Set(constants.CTXFLG_USER_NAME, username)
|
c.Set(eum.CtxUserName, username)
|
||||||
c.Set(constants.CTXFLG_ROLE, repository.UserRepository.GetUserByName(username).Role)
|
c.Set(eum.CtxRole, repository.UserRepository.GetUserByName(username).Role)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
|
19
internal/app/model/event.go
Normal file
19
internal/app/model/event.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
Id uint64 `gorm:"primaryKey;autoIncrement;column:id" json:"id"`
|
||||||
|
Name string `gorm:"column:name" json:"name"`
|
||||||
|
Type eum.EventType `gorm:"column:type" json:"type"`
|
||||||
|
Additional string `gorm:"column:additional" json:"additional"`
|
||||||
|
CreatedTime time.Time `gorm:"column:created_time" json:"createdTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Event) TableName() string {
|
||||||
|
return "event"
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "github.com/lzh-1625/go_process_manager/internal/app/constants"
|
import "github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
|
|
||||||
type ProcessInfo struct {
|
type ProcessInfo struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@@ -9,7 +9,7 @@ type ProcessInfo struct {
|
|||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
Usage Usage `json:"usage"`
|
Usage Usage `json:"usage"`
|
||||||
State State `json:"state"`
|
State State `json:"state"`
|
||||||
TermType constants.TerminalType `json:"termType"`
|
TermType eum.TerminalType `json:"termType"`
|
||||||
CgroupEnable bool `json:"cgroupEnable"`
|
CgroupEnable bool `json:"cgroupEnable"`
|
||||||
MemoryLimit *float32 `json:"memoryLimit"`
|
MemoryLimit *float32 `json:"memoryLimit"`
|
||||||
CpuLimit *float32 `json:"cpuLimit"`
|
CpuLimit *float32 `json:"cpuLimit"`
|
||||||
@@ -24,6 +24,6 @@ type Usage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
State constants.ProcessState `json:"state"`
|
State eum.ProcessState `json:"state"`
|
||||||
Info string `json:"info"`
|
Info string `json:"info"`
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import "github.com/lzh-1625/go_process_manager/internal/app/constants"
|
import "github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
|
|
||||||
type Process struct {
|
type Process struct {
|
||||||
Uuid int `gorm:"primaryKey;autoIncrement;column:uuid" json:"uuid"`
|
Uuid int `gorm:"primaryKey;autoIncrement;column:uuid" json:"uuid"`
|
||||||
@@ -11,7 +11,7 @@ type Process struct {
|
|||||||
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"`
|
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"`
|
||||||
PushIds string `gorm:"column:push_ids" json:"pushIds"`
|
PushIds string `gorm:"column:push_ids" json:"pushIds"`
|
||||||
LogReport bool `gorm:"column:log_report" json:"logReport"`
|
LogReport bool `gorm:"column:log_report" json:"logReport"`
|
||||||
TermType constants.TerminalType `gorm:"column:term_type" json:"termType"`
|
TermType eum.TerminalType `gorm:"column:term_type" json:"termType"`
|
||||||
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`
|
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`
|
||||||
MemoryLimit *float32 `gorm:"column:memory_limit" json:"memoryLimit"`
|
MemoryLimit *float32 `gorm:"column:memory_limit" json:"memoryLimit"`
|
||||||
CpuLimit *float32 `gorm:"column:cpu_limit" json:"cpuLimit"`
|
CpuLimit *float32 `gorm:"column:cpu_limit" json:"cpuLimit"`
|
||||||
|
@@ -3,16 +3,17 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Id int `gorm:"column:id;NOT NULL;primaryKey;autoIncrement;" json:"id" `
|
Id int `gorm:"column:id;NOT NULL;primaryKey;autoIncrement;" json:"id" `
|
||||||
|
Name string `gorm:"column:name" json:"name" `
|
||||||
ProcessId int `gorm:"column:process_id;NOT NULL" json:"processId" `
|
ProcessId int `gorm:"column:process_id;NOT NULL" json:"processId" `
|
||||||
Condition constants.Condition `gorm:"column:condition;NOT NULL" json:"condition" `
|
Condition eum.Condition `gorm:"column:condition;NOT NULL" json:"condition" `
|
||||||
NextId *int `gorm:"column:next_id;" json:"nextId" `
|
NextId *int `gorm:"column:next_id;" json:"nextId" `
|
||||||
Operation constants.TaskOperation `gorm:"column:operation;NOT NULL" json:"operation" `
|
Operation eum.TaskOperation `gorm:"column:operation;NOT NULL" json:"operation" `
|
||||||
TriggerEvent *constants.ProcessState `gorm:"column:trigger_event;" json:"triggerEvent" `
|
TriggerEvent *eum.ProcessState `gorm:"column:trigger_event;" json:"triggerEvent" `
|
||||||
TriggerTarget *int `gorm:"column:trigger_target;" json:"triggerTarget" `
|
TriggerTarget *int `gorm:"column:trigger_target;" json:"triggerTarget" `
|
||||||
OperationTarget int `gorm:"column:operation_target;NOT NULL" json:"operationTarget" `
|
OperationTarget int `gorm:"column:operation_target;NOT NULL" json:"operationTarget" `
|
||||||
CronExpression string `gorm:"column:cron;" json:"cron" `
|
CronExpression string `gorm:"column:cron;" json:"cron" `
|
||||||
|
@@ -3,13 +3,13 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Account string `json:"account" gorm:"primaryKey;column:account" `
|
Account string `json:"account" gorm:"primaryKey;column:account" `
|
||||||
Password string `json:"password" gorm:"column:password" `
|
Password string `json:"password" gorm:"column:password" `
|
||||||
Role constants.Role `json:"role" gorm:"column:role" `
|
Role eum.Role `json:"role" gorm:"column:role" `
|
||||||
CreateTime time.Time `json:"createTime" gorm:"column:create_time" `
|
CreateTime time.Time `json:"createTime" gorm:"column:create_time" `
|
||||||
Remark string `json:"remark" gorm:"column:remark" `
|
Remark string `json:"remark" gorm:"column:remark" `
|
||||||
}
|
}
|
||||||
|
@@ -42,14 +42,17 @@ func InitDb() {
|
|||||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||||
db = gdb.Session(&defaultConfig)
|
db = gdb.Session(&defaultConfig)
|
||||||
// db = db.Debug()
|
// db = db.Debug()
|
||||||
db.AutoMigrate(&model.Process{}, &model.User{}, &model.Permission{}, &model.Push{}, &model.Config{}, &model.ProcessLog{}, &model.Task{}, &model.WsShare{})
|
db.AutoMigrate(
|
||||||
|
&model.Process{},
|
||||||
// g := gen.NewGenerator(gen.Config{
|
&model.User{},
|
||||||
// OutPath: "internal/app/repository/query",
|
&model.Permission{},
|
||||||
// Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
|
&model.Push{},
|
||||||
// })
|
&model.Config{},
|
||||||
// g.UseDB(db)
|
&model.ProcessLog{},
|
||||||
// g.ApplyBasic(&model.Process{}, &model.User{}, &model.Permission{}, &model.Push{}, &model.Config{}, &model.ProcessLog{}, &model.Task{}, &model.WsShare{})
|
&model.Task{},
|
||||||
// g.Execute()
|
&model.WsShare{},
|
||||||
|
&model.Event{},
|
||||||
|
)
|
||||||
|
gormGen(db)
|
||||||
query.SetDefault(db)
|
query.SetDefault(db)
|
||||||
}
|
}
|
||||||
|
14
internal/app/repository/event.go
Normal file
14
internal/app/repository/event.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
||||||
|
)
|
||||||
|
|
||||||
|
type eventRepository struct{}
|
||||||
|
|
||||||
|
var EventRepository = new(eventRepository)
|
||||||
|
|
||||||
|
func (e *eventRepository) Create(event model.Event) error {
|
||||||
|
return query.Event.Create(&event)
|
||||||
|
}
|
33
internal/app/repository/gen.go
Normal file
33
internal/app/repository/gen.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
//go:build gen
|
||||||
|
// +build gen
|
||||||
|
|
||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
"gorm.io/gen"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func gormGen(db *gorm.DB) {
|
||||||
|
g := gen.NewGenerator(gen.Config{
|
||||||
|
OutPath: "internal/app/repository/query",
|
||||||
|
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
|
||||||
|
})
|
||||||
|
g.UseDB(db)
|
||||||
|
g.ApplyBasic(
|
||||||
|
&model.Process{},
|
||||||
|
&model.User{},
|
||||||
|
&model.Permission{},
|
||||||
|
&model.Push{},
|
||||||
|
&model.Config{},
|
||||||
|
&model.ProcessLog{},
|
||||||
|
&model.Task{},
|
||||||
|
&model.WsShare{},
|
||||||
|
&model.Event{},
|
||||||
|
)
|
||||||
|
g.Execute()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
10
internal/app/repository/gen_ignore.go
Normal file
10
internal/app/repository/gen_ignore.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build !gen
|
||||||
|
// +build !gen
|
||||||
|
|
||||||
|
package repository
|
||||||
|
|
||||||
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
|
func gormGen(*gorm.DB) {
|
||||||
|
|
||||||
|
}
|
@@ -3,7 +3,7 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
@@ -64,18 +64,18 @@ func (p *permissionRepository) GetPermission(user string, pid int) (result model
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *permissionRepository) GetProcessNameByPermission(user string, op constants.OprPermission) (result []string) {
|
func (p *permissionRepository) GetProcessNameByPermission(user string, op eum.OprPermission) (result []string) {
|
||||||
tx := query.Permission.Select(query.Process.Name).RightJoin(query.Process, query.Process.Uuid.EqCol(query.Permission.Pid)).Where(query.Permission.Account.Eq(user)).Where(query.Permission.Owned.Is(true))
|
tx := query.Permission.Select(query.Process.Name).RightJoin(query.Process, query.Process.Uuid.EqCol(query.Permission.Pid)).Where(query.Permission.Account.Eq(user)).Where(query.Permission.Owned.Is(true))
|
||||||
switch op {
|
switch op {
|
||||||
case constants.OPERATION_LOG:
|
case eum.OperationLog:
|
||||||
tx = tx.Where(query.Permission.Log.Is(true))
|
tx = tx.Where(query.Permission.Log.Is(true))
|
||||||
case constants.OPERATION_START:
|
case eum.OperationStart:
|
||||||
tx = tx.Where(query.Permission.Start.Is(true))
|
tx = tx.Where(query.Permission.Start.Is(true))
|
||||||
case constants.OPERATION_STOP:
|
case eum.OperationStop:
|
||||||
tx = tx.Where(query.Permission.Stop.Is(true))
|
tx = tx.Where(query.Permission.Stop.Is(true))
|
||||||
case constants.OPERATION_TERMINAL:
|
case eum.OperationTerminal:
|
||||||
tx = tx.Where(query.Permission.Terminal.Is(true))
|
tx = tx.Where(query.Permission.Terminal.Is(true))
|
||||||
case constants.OPERATION_TERMINAL_WRITE:
|
case eum.OperationTerminalWrite:
|
||||||
tx = tx.Where(query.Permission.Write.Is(true))
|
tx = tx.Where(query.Permission.Write.Is(true))
|
||||||
}
|
}
|
||||||
tx.Scan(&result)
|
tx.Scan(&result)
|
||||||
|
398
internal/app/repository/query/event.gen.go
Normal file
398
internal/app/repository/query/event.gen.go
Normal file
@@ -0,0 +1,398 @@
|
|||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||||
|
|
||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
|
||||||
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"gorm.io/gorm/clause"
|
||||||
|
"gorm.io/gorm/schema"
|
||||||
|
|
||||||
|
"gorm.io/gen"
|
||||||
|
"gorm.io/gen/field"
|
||||||
|
|
||||||
|
"gorm.io/plugin/dbresolver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newEvent(db *gorm.DB, opts ...gen.DOOption) event {
|
||||||
|
_event := event{}
|
||||||
|
|
||||||
|
_event.eventDo.UseDB(db, opts...)
|
||||||
|
_event.eventDo.UseModel(&model.Event{})
|
||||||
|
|
||||||
|
tableName := _event.eventDo.TableName()
|
||||||
|
_event.ALL = field.NewAsterisk(tableName)
|
||||||
|
_event.Id = field.NewUint64(tableName, "id")
|
||||||
|
_event.Name = field.NewString(tableName, "name")
|
||||||
|
_event.Type = field.NewString(tableName, "type")
|
||||||
|
_event.Additional = field.NewString(tableName, "additional")
|
||||||
|
_event.CreatedTime = field.NewTime(tableName, "created_time")
|
||||||
|
|
||||||
|
_event.fillFieldMap()
|
||||||
|
|
||||||
|
return _event
|
||||||
|
}
|
||||||
|
|
||||||
|
type event struct {
|
||||||
|
eventDo
|
||||||
|
|
||||||
|
ALL field.Asterisk
|
||||||
|
Id field.Uint64
|
||||||
|
Name field.String
|
||||||
|
Type field.String
|
||||||
|
Additional field.String
|
||||||
|
CreatedTime field.Time
|
||||||
|
|
||||||
|
fieldMap map[string]field.Expr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e event) Table(newTableName string) *event {
|
||||||
|
e.eventDo.UseTable(newTableName)
|
||||||
|
return e.updateTableName(newTableName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e event) As(alias string) *event {
|
||||||
|
e.eventDo.DO = *(e.eventDo.As(alias).(*gen.DO))
|
||||||
|
return e.updateTableName(alias)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *event) updateTableName(table string) *event {
|
||||||
|
e.ALL = field.NewAsterisk(table)
|
||||||
|
e.Id = field.NewUint64(table, "id")
|
||||||
|
e.Name = field.NewString(table, "name")
|
||||||
|
e.Type = field.NewString(table, "type")
|
||||||
|
e.Additional = field.NewString(table, "additional")
|
||||||
|
e.CreatedTime = field.NewTime(table, "created_time")
|
||||||
|
|
||||||
|
e.fillFieldMap()
|
||||||
|
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *event) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||||
|
_f, ok := e.fieldMap[fieldName]
|
||||||
|
if !ok || _f == nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
_oe, ok := _f.(field.OrderExpr)
|
||||||
|
return _oe, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *event) fillFieldMap() {
|
||||||
|
e.fieldMap = make(map[string]field.Expr, 5)
|
||||||
|
e.fieldMap["id"] = e.Id
|
||||||
|
e.fieldMap["name"] = e.Name
|
||||||
|
e.fieldMap["type"] = e.Type
|
||||||
|
e.fieldMap["additional"] = e.Additional
|
||||||
|
e.fieldMap["created_time"] = e.CreatedTime
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e event) clone(db *gorm.DB) event {
|
||||||
|
e.eventDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e event) replaceDB(db *gorm.DB) event {
|
||||||
|
e.eventDo.ReplaceDB(db)
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
type eventDo struct{ gen.DO }
|
||||||
|
|
||||||
|
type IEventDo interface {
|
||||||
|
gen.SubQuery
|
||||||
|
Debug() IEventDo
|
||||||
|
WithContext(ctx context.Context) IEventDo
|
||||||
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
||||||
|
ReplaceDB(db *gorm.DB)
|
||||||
|
ReadDB() IEventDo
|
||||||
|
WriteDB() IEventDo
|
||||||
|
As(alias string) gen.Dao
|
||||||
|
Session(config *gorm.Session) IEventDo
|
||||||
|
Columns(cols ...field.Expr) gen.Columns
|
||||||
|
Clauses(conds ...clause.Expression) IEventDo
|
||||||
|
Not(conds ...gen.Condition) IEventDo
|
||||||
|
Or(conds ...gen.Condition) IEventDo
|
||||||
|
Select(conds ...field.Expr) IEventDo
|
||||||
|
Where(conds ...gen.Condition) IEventDo
|
||||||
|
Order(conds ...field.Expr) IEventDo
|
||||||
|
Distinct(cols ...field.Expr) IEventDo
|
||||||
|
Omit(cols ...field.Expr) IEventDo
|
||||||
|
Join(table schema.Tabler, on ...field.Expr) IEventDo
|
||||||
|
LeftJoin(table schema.Tabler, on ...field.Expr) IEventDo
|
||||||
|
RightJoin(table schema.Tabler, on ...field.Expr) IEventDo
|
||||||
|
Group(cols ...field.Expr) IEventDo
|
||||||
|
Having(conds ...gen.Condition) IEventDo
|
||||||
|
Limit(limit int) IEventDo
|
||||||
|
Offset(offset int) IEventDo
|
||||||
|
Count() (count int64, err error)
|
||||||
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IEventDo
|
||||||
|
Unscoped() IEventDo
|
||||||
|
Create(values ...*model.Event) error
|
||||||
|
CreateInBatches(values []*model.Event, batchSize int) error
|
||||||
|
Save(values ...*model.Event) error
|
||||||
|
First() (*model.Event, error)
|
||||||
|
Take() (*model.Event, error)
|
||||||
|
Last() (*model.Event, error)
|
||||||
|
Find() ([]*model.Event, error)
|
||||||
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Event, err error)
|
||||||
|
FindInBatches(result *[]*model.Event, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
||||||
|
Pluck(column field.Expr, dest interface{}) error
|
||||||
|
Delete(...*model.Event) (info gen.ResultInfo, err error)
|
||||||
|
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||||
|
Updates(value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
||||||
|
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
||||||
|
UpdateFrom(q gen.SubQuery) gen.Dao
|
||||||
|
Attrs(attrs ...field.AssignExpr) IEventDo
|
||||||
|
Assign(attrs ...field.AssignExpr) IEventDo
|
||||||
|
Joins(fields ...field.RelationField) IEventDo
|
||||||
|
Preload(fields ...field.RelationField) IEventDo
|
||||||
|
FirstOrInit() (*model.Event, error)
|
||||||
|
FirstOrCreate() (*model.Event, error)
|
||||||
|
FindByPage(offset int, limit int) (result []*model.Event, count int64, err error)
|
||||||
|
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
||||||
|
Rows() (*sql.Rows, error)
|
||||||
|
Row() *sql.Row
|
||||||
|
Scan(result interface{}) (err error)
|
||||||
|
Returning(value interface{}, columns ...string) IEventDo
|
||||||
|
UnderlyingDB() *gorm.DB
|
||||||
|
schema.Tabler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Debug() IEventDo {
|
||||||
|
return e.withDO(e.DO.Debug())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) WithContext(ctx context.Context) IEventDo {
|
||||||
|
return e.withDO(e.DO.WithContext(ctx))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) ReadDB() IEventDo {
|
||||||
|
return e.Clauses(dbresolver.Read)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) WriteDB() IEventDo {
|
||||||
|
return e.Clauses(dbresolver.Write)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Session(config *gorm.Session) IEventDo {
|
||||||
|
return e.withDO(e.DO.Session(config))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Clauses(conds ...clause.Expression) IEventDo {
|
||||||
|
return e.withDO(e.DO.Clauses(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Returning(value interface{}, columns ...string) IEventDo {
|
||||||
|
return e.withDO(e.DO.Returning(value, columns...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Not(conds ...gen.Condition) IEventDo {
|
||||||
|
return e.withDO(e.DO.Not(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Or(conds ...gen.Condition) IEventDo {
|
||||||
|
return e.withDO(e.DO.Or(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Select(conds ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Select(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Where(conds ...gen.Condition) IEventDo {
|
||||||
|
return e.withDO(e.DO.Where(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Order(conds ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Order(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Distinct(cols ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Distinct(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Omit(cols ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Omit(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Join(table schema.Tabler, on ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Join(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) LeftJoin(table schema.Tabler, on ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.LeftJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) RightJoin(table schema.Tabler, on ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.RightJoin(table, on...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Group(cols ...field.Expr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Group(cols...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Having(conds ...gen.Condition) IEventDo {
|
||||||
|
return e.withDO(e.DO.Having(conds...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Limit(limit int) IEventDo {
|
||||||
|
return e.withDO(e.DO.Limit(limit))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Offset(offset int) IEventDo {
|
||||||
|
return e.withDO(e.DO.Offset(offset))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IEventDo {
|
||||||
|
return e.withDO(e.DO.Scopes(funcs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Unscoped() IEventDo {
|
||||||
|
return e.withDO(e.DO.Unscoped())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Create(values ...*model.Event) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return e.DO.Create(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) CreateInBatches(values []*model.Event, batchSize int) error {
|
||||||
|
return e.DO.CreateInBatches(values, batchSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save : !!! underlying implementation is different with GORM
|
||||||
|
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||||
|
func (e eventDo) Save(values ...*model.Event) error {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return e.DO.Save(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) First() (*model.Event, error) {
|
||||||
|
if result, err := e.DO.First(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*model.Event), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Take() (*model.Event, error) {
|
||||||
|
if result, err := e.DO.Take(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*model.Event), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Last() (*model.Event, error) {
|
||||||
|
if result, err := e.DO.Last(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*model.Event), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Find() ([]*model.Event, error) {
|
||||||
|
result, err := e.DO.Find()
|
||||||
|
return result.([]*model.Event), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Event, err error) {
|
||||||
|
buf := make([]*model.Event, 0, batchSize)
|
||||||
|
err = e.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||||
|
defer func() { results = append(results, buf...) }()
|
||||||
|
return fc(tx, batch)
|
||||||
|
})
|
||||||
|
return results, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) FindInBatches(result *[]*model.Event, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||||
|
return e.DO.FindInBatches(result, batchSize, fc)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Attrs(attrs ...field.AssignExpr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Attrs(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Assign(attrs ...field.AssignExpr) IEventDo {
|
||||||
|
return e.withDO(e.DO.Assign(attrs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Joins(fields ...field.RelationField) IEventDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
e = *e.withDO(e.DO.Joins(_f))
|
||||||
|
}
|
||||||
|
return &e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Preload(fields ...field.RelationField) IEventDo {
|
||||||
|
for _, _f := range fields {
|
||||||
|
e = *e.withDO(e.DO.Preload(_f))
|
||||||
|
}
|
||||||
|
return &e
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) FirstOrInit() (*model.Event, error) {
|
||||||
|
if result, err := e.DO.FirstOrInit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*model.Event), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) FirstOrCreate() (*model.Event, error) {
|
||||||
|
if result, err := e.DO.FirstOrCreate(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return result.(*model.Event), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) FindByPage(offset int, limit int) (result []*model.Event, count int64, err error) {
|
||||||
|
result, err = e.Offset(offset).Limit(limit).Find()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||||
|
count = int64(size + offset)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
count, err = e.Offset(-1).Limit(-1).Count()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||||
|
count, err = e.Count()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = e.Offset(offset).Limit(limit).Scan(result)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Scan(result interface{}) (err error) {
|
||||||
|
return e.DO.Scan(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e eventDo) Delete(models ...*model.Event) (result gen.ResultInfo, err error) {
|
||||||
|
return e.DO.Delete(models)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *eventDo) withDO(do gen.Dao) *eventDo {
|
||||||
|
e.DO = *do.(*gen.DO)
|
||||||
|
return e
|
||||||
|
}
|
@@ -18,6 +18,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
Q = new(Query)
|
Q = new(Query)
|
||||||
Config *config
|
Config *config
|
||||||
|
Event *event
|
||||||
Permission *permission
|
Permission *permission
|
||||||
Process *process
|
Process *process
|
||||||
ProcessLog *processLog
|
ProcessLog *processLog
|
||||||
@@ -30,6 +31,7 @@ var (
|
|||||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||||
*Q = *Use(db, opts...)
|
*Q = *Use(db, opts...)
|
||||||
Config = &Q.Config
|
Config = &Q.Config
|
||||||
|
Event = &Q.Event
|
||||||
Permission = &Q.Permission
|
Permission = &Q.Permission
|
||||||
Process = &Q.Process
|
Process = &Q.Process
|
||||||
ProcessLog = &Q.ProcessLog
|
ProcessLog = &Q.ProcessLog
|
||||||
@@ -43,6 +45,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Config: newConfig(db, opts...),
|
Config: newConfig(db, opts...),
|
||||||
|
Event: newEvent(db, opts...),
|
||||||
Permission: newPermission(db, opts...),
|
Permission: newPermission(db, opts...),
|
||||||
Process: newProcess(db, opts...),
|
Process: newProcess(db, opts...),
|
||||||
ProcessLog: newProcessLog(db, opts...),
|
ProcessLog: newProcessLog(db, opts...),
|
||||||
@@ -57,6 +60,7 @@ type Query struct {
|
|||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
|
||||||
Config config
|
Config config
|
||||||
|
Event event
|
||||||
Permission permission
|
Permission permission
|
||||||
Process process
|
Process process
|
||||||
ProcessLog processLog
|
ProcessLog processLog
|
||||||
@@ -72,6 +76,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
|||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Config: q.Config.clone(db),
|
Config: q.Config.clone(db),
|
||||||
|
Event: q.Event.clone(db),
|
||||||
Permission: q.Permission.clone(db),
|
Permission: q.Permission.clone(db),
|
||||||
Process: q.Process.clone(db),
|
Process: q.Process.clone(db),
|
||||||
ProcessLog: q.ProcessLog.clone(db),
|
ProcessLog: q.ProcessLog.clone(db),
|
||||||
@@ -94,6 +99,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|||||||
return &Query{
|
return &Query{
|
||||||
db: db,
|
db: db,
|
||||||
Config: q.Config.replaceDB(db),
|
Config: q.Config.replaceDB(db),
|
||||||
|
Event: q.Event.replaceDB(db),
|
||||||
Permission: q.Permission.replaceDB(db),
|
Permission: q.Permission.replaceDB(db),
|
||||||
Process: q.Process.replaceDB(db),
|
Process: q.Process.replaceDB(db),
|
||||||
ProcessLog: q.ProcessLog.replaceDB(db),
|
ProcessLog: q.ProcessLog.replaceDB(db),
|
||||||
@@ -106,6 +112,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|||||||
|
|
||||||
type queryCtx struct {
|
type queryCtx struct {
|
||||||
Config IConfigDo
|
Config IConfigDo
|
||||||
|
Event IEventDo
|
||||||
Permission IPermissionDo
|
Permission IPermissionDo
|
||||||
Process IProcessDo
|
Process IProcessDo
|
||||||
ProcessLog IProcessLogDo
|
ProcessLog IProcessLogDo
|
||||||
@@ -118,6 +125,7 @@ type queryCtx struct {
|
|||||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||||
return &queryCtx{
|
return &queryCtx{
|
||||||
Config: q.Config.WithContext(ctx),
|
Config: q.Config.WithContext(ctx),
|
||||||
|
Event: q.Event.WithContext(ctx),
|
||||||
Permission: q.Permission.WithContext(ctx),
|
Permission: q.Permission.WithContext(ctx),
|
||||||
Process: q.Process.WithContext(ctx),
|
Process: q.Process.WithContext(ctx),
|
||||||
ProcessLog: q.ProcessLog.WithContext(ctx),
|
ProcessLog: q.ProcessLog.WithContext(ctx),
|
||||||
|
@@ -28,6 +28,7 @@ func newTask(db *gorm.DB, opts ...gen.DOOption) task {
|
|||||||
tableName := _task.taskDo.TableName()
|
tableName := _task.taskDo.TableName()
|
||||||
_task.ALL = field.NewAsterisk(tableName)
|
_task.ALL = field.NewAsterisk(tableName)
|
||||||
_task.Id = field.NewInt(tableName, "id")
|
_task.Id = field.NewInt(tableName, "id")
|
||||||
|
_task.Name = field.NewString(tableName, "name")
|
||||||
_task.ProcessId = field.NewInt(tableName, "process_id")
|
_task.ProcessId = field.NewInt(tableName, "process_id")
|
||||||
_task.Condition = field.NewInt(tableName, "condition")
|
_task.Condition = field.NewInt(tableName, "condition")
|
||||||
_task.NextId = field.NewInt(tableName, "next_id")
|
_task.NextId = field.NewInt(tableName, "next_id")
|
||||||
@@ -35,7 +36,7 @@ func newTask(db *gorm.DB, opts ...gen.DOOption) task {
|
|||||||
_task.TriggerEvent = field.NewInt32(tableName, "trigger_event")
|
_task.TriggerEvent = field.NewInt32(tableName, "trigger_event")
|
||||||
_task.TriggerTarget = field.NewInt(tableName, "trigger_target")
|
_task.TriggerTarget = field.NewInt(tableName, "trigger_target")
|
||||||
_task.OperationTarget = field.NewInt(tableName, "operation_target")
|
_task.OperationTarget = field.NewInt(tableName, "operation_target")
|
||||||
_task.Cron = field.NewString(tableName, "cron")
|
_task.CronExpression = field.NewString(tableName, "cron")
|
||||||
_task.Enable = field.NewBool(tableName, "enable")
|
_task.Enable = field.NewBool(tableName, "enable")
|
||||||
_task.ApiEnable = field.NewBool(tableName, "api_enable")
|
_task.ApiEnable = field.NewBool(tableName, "api_enable")
|
||||||
_task.Key = field.NewString(tableName, "key")
|
_task.Key = field.NewString(tableName, "key")
|
||||||
@@ -50,6 +51,7 @@ type task struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
Id field.Int
|
Id field.Int
|
||||||
|
Name field.String
|
||||||
ProcessId field.Int
|
ProcessId field.Int
|
||||||
Condition field.Int
|
Condition field.Int
|
||||||
NextId field.Int
|
NextId field.Int
|
||||||
@@ -57,7 +59,7 @@ type task struct {
|
|||||||
TriggerEvent field.Int32
|
TriggerEvent field.Int32
|
||||||
TriggerTarget field.Int
|
TriggerTarget field.Int
|
||||||
OperationTarget field.Int
|
OperationTarget field.Int
|
||||||
Cron field.String
|
CronExpression field.String
|
||||||
Enable field.Bool
|
Enable field.Bool
|
||||||
ApiEnable field.Bool
|
ApiEnable field.Bool
|
||||||
Key field.String
|
Key field.String
|
||||||
@@ -78,6 +80,7 @@ func (t task) As(alias string) *task {
|
|||||||
func (t *task) updateTableName(table string) *task {
|
func (t *task) updateTableName(table string) *task {
|
||||||
t.ALL = field.NewAsterisk(table)
|
t.ALL = field.NewAsterisk(table)
|
||||||
t.Id = field.NewInt(table, "id")
|
t.Id = field.NewInt(table, "id")
|
||||||
|
t.Name = field.NewString(table, "name")
|
||||||
t.ProcessId = field.NewInt(table, "process_id")
|
t.ProcessId = field.NewInt(table, "process_id")
|
||||||
t.Condition = field.NewInt(table, "condition")
|
t.Condition = field.NewInt(table, "condition")
|
||||||
t.NextId = field.NewInt(table, "next_id")
|
t.NextId = field.NewInt(table, "next_id")
|
||||||
@@ -85,7 +88,7 @@ func (t *task) updateTableName(table string) *task {
|
|||||||
t.TriggerEvent = field.NewInt32(table, "trigger_event")
|
t.TriggerEvent = field.NewInt32(table, "trigger_event")
|
||||||
t.TriggerTarget = field.NewInt(table, "trigger_target")
|
t.TriggerTarget = field.NewInt(table, "trigger_target")
|
||||||
t.OperationTarget = field.NewInt(table, "operation_target")
|
t.OperationTarget = field.NewInt(table, "operation_target")
|
||||||
t.Cron = field.NewString(table, "cron")
|
t.CronExpression = field.NewString(table, "cron")
|
||||||
t.Enable = field.NewBool(table, "enable")
|
t.Enable = field.NewBool(table, "enable")
|
||||||
t.ApiEnable = field.NewBool(table, "api_enable")
|
t.ApiEnable = field.NewBool(table, "api_enable")
|
||||||
t.Key = field.NewString(table, "key")
|
t.Key = field.NewString(table, "key")
|
||||||
@@ -105,8 +108,9 @@ func (t *task) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) fillFieldMap() {
|
func (t *task) fillFieldMap() {
|
||||||
t.fieldMap = make(map[string]field.Expr, 12)
|
t.fieldMap = make(map[string]field.Expr, 13)
|
||||||
t.fieldMap["id"] = t.Id
|
t.fieldMap["id"] = t.Id
|
||||||
|
t.fieldMap["name"] = t.Name
|
||||||
t.fieldMap["process_id"] = t.ProcessId
|
t.fieldMap["process_id"] = t.ProcessId
|
||||||
t.fieldMap["condition"] = t.Condition
|
t.fieldMap["condition"] = t.Condition
|
||||||
t.fieldMap["next_id"] = t.NextId
|
t.fieldMap["next_id"] = t.NextId
|
||||||
@@ -114,7 +118,7 @@ func (t *task) fillFieldMap() {
|
|||||||
t.fieldMap["trigger_event"] = t.TriggerEvent
|
t.fieldMap["trigger_event"] = t.TriggerEvent
|
||||||
t.fieldMap["trigger_target"] = t.TriggerTarget
|
t.fieldMap["trigger_target"] = t.TriggerTarget
|
||||||
t.fieldMap["operation_target"] = t.OperationTarget
|
t.fieldMap["operation_target"] = t.OperationTarget
|
||||||
t.fieldMap["cron"] = t.Cron
|
t.fieldMap["cron"] = t.CronExpression
|
||||||
t.fieldMap["enable"] = t.Enable
|
t.fieldMap["enable"] = t.Enable
|
||||||
t.fieldMap["api_enable"] = t.ApiEnable
|
t.fieldMap["api_enable"] = t.ApiEnable
|
||||||
t.fieldMap["key"] = t.Key
|
t.fieldMap["key"] = t.Key
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
||||||
)
|
)
|
||||||
@@ -64,7 +64,7 @@ func (t *taskRepository) GetAllTaskWithProcessName() (result []model.TaskVo) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *taskRepository) GetTriggerTask(processName string, event constants.ProcessState) []model.Task {
|
func (t *taskRepository) GetTriggerTask(processName string, event eum.ProcessState) []model.Task {
|
||||||
result := []model.Task{}
|
result := []model.Task{}
|
||||||
query.Task.Select(query.Task.ALL).
|
query.Task.Select(query.Task.ALL).
|
||||||
LeftJoin(query.Process, query.Process.Uuid.EqCol(query.Task.TriggerTarget)).
|
LeftJoin(query.Process, query.Process.Uuid.EqCol(query.Task.TriggerTarget)).
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/api"
|
"github.com/lzh-1625/go_process_manager/internal/app/api"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
"github.com/lzh-1625/go_process_manager/internal/app/middle"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/resources"
|
"github.com/lzh-1625/go_process_manager/resources"
|
||||||
@@ -58,55 +58,55 @@ func routePathInit(r *gin.Engine) {
|
|||||||
{
|
{
|
||||||
wsGroup := apiGroup.Group("/ws")
|
wsGroup := apiGroup.Group("/ws")
|
||||||
{
|
{
|
||||||
wsGroup.GET("", middle.OprPermission(constants.OPERATION_TERMINAL), bind(api.WsApi.WebsocketHandle, Query))
|
wsGroup.GET("", middle.OprPermission(eum.OperationTerminal), bind(api.WsApi.WebsocketHandle, Query))
|
||||||
wsGroup.GET("/share", bind(api.WsApi.WebsocketShareHandle, Query))
|
wsGroup.GET("/share", bind(api.WsApi.WebsocketShareHandle, Query))
|
||||||
}
|
}
|
||||||
|
|
||||||
processGroup := apiGroup.Group("/process")
|
processGroup := apiGroup.Group("/process")
|
||||||
{
|
{
|
||||||
processGroup.DELETE("", middle.OprPermission(constants.OPERATION_STOP), bind(api.ProcApi.KillProcess, Query))
|
processGroup.DELETE("", middle.OprPermission(eum.OperationStop), bind(api.ProcApi.KillProcess, Query))
|
||||||
processGroup.GET("", bind(api.ProcApi.GetProcessList, None))
|
processGroup.GET("", bind(api.ProcApi.GetProcessList, None))
|
||||||
processGroup.GET("/wait", middle.ProcessWaitCond.WaitGetMiddel, bind(api.ProcApi.GetProcessList, None))
|
processGroup.GET("/wait", middle.ProcessWaitCond.WaitGetMiddel, bind(api.ProcApi.GetProcessList, None))
|
||||||
processGroup.PUT("", middle.OprPermission(constants.OPERATION_START), bind(api.ProcApi.StartProcess, Query))
|
processGroup.PUT("", middle.OprPermission(eum.OperationStart), bind(api.ProcApi.StartProcess, Query))
|
||||||
processGroup.PUT("/all", bind(api.ProcApi.StartAllProcess, None))
|
processGroup.PUT("/all", bind(api.ProcApi.StartAllProcess, None))
|
||||||
processGroup.DELETE("/all", bind(api.ProcApi.KillAllProcess, None))
|
processGroup.DELETE("/all", bind(api.ProcApi.KillAllProcess, None))
|
||||||
processGroup.POST("/share", middle.RolePermission(constants.ROLE_ADMIN), bind(api.ProcApi.ProcessCreateShare, Body))
|
processGroup.POST("/share", middle.RolePermission(eum.RoleAdmin), bind(api.ProcApi.ProcessCreateShare, Body))
|
||||||
processGroup.GET("/control", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.ProcessControl, Query))
|
processGroup.GET("/control", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.ProcessControl, Query))
|
||||||
|
|
||||||
proConfigGroup := processGroup.Group("/config")
|
proConfigGroup := processGroup.Group("/config")
|
||||||
{
|
{
|
||||||
proConfigGroup.POST("", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.CreateNewProcess, Body))
|
proConfigGroup.POST("", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.CreateNewProcess, Body))
|
||||||
proConfigGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.DeleteNewProcess, Query))
|
proConfigGroup.DELETE("", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.DeleteNewProcess, Query))
|
||||||
proConfigGroup.PUT("", middle.RolePermission(constants.ROLE_ROOT), bind(api.ProcApi.UpdateProcessConfig, Body))
|
proConfigGroup.PUT("", middle.RolePermission(eum.RoleRoot), bind(api.ProcApi.UpdateProcessConfig, Body))
|
||||||
proConfigGroup.GET("", middle.RolePermission(constants.ROLE_ADMIN), bind(api.ProcApi.GetProcessConfig, Query))
|
proConfigGroup.GET("", middle.RolePermission(eum.RoleAdmin), bind(api.ProcApi.GetProcessConfig, Query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taskGroup := apiGroup.Group("/task")
|
taskGroup := apiGroup.Group("/task")
|
||||||
{
|
{
|
||||||
taskGroup.GET("", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.GetTaskById, Query))
|
taskGroup.GET("", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.GetTaskById, Query))
|
||||||
taskGroup.GET("/all", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.GetTaskList, None))
|
taskGroup.GET("/all", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.GetTaskList, None))
|
||||||
taskGroup.GET("/all/wait", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitGetMiddel, bind(api.TaskApi.GetTaskList, None))
|
taskGroup.GET("/all/wait", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitGetMiddel, bind(api.TaskApi.GetTaskList, None))
|
||||||
taskGroup.POST("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.CreateTask, Body))
|
taskGroup.POST("", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.CreateTask, Body))
|
||||||
taskGroup.DELETE("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.DeleteTaskById, Query))
|
taskGroup.DELETE("", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.DeleteTaskById, Query))
|
||||||
taskGroup.PUT("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTask, Body))
|
taskGroup.PUT("", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTask, Body))
|
||||||
taskGroup.PUT("/enable", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTaskEnable, Body))
|
taskGroup.PUT("/enable", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTaskEnable, Body))
|
||||||
taskGroup.GET("/start", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.StartTask, Query))
|
taskGroup.GET("/start", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.StartTask, Query))
|
||||||
taskGroup.GET("/stop", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.StopTask, Query))
|
taskGroup.GET("/stop", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.StopTask, Query))
|
||||||
taskGroup.POST("/key", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.CreateTaskApiKey, Body))
|
taskGroup.POST("/key", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.CreateTaskApiKey, Body))
|
||||||
taskGroup.GET("/api-key/:key", bind(api.TaskApi.RunTaskByKey, None))
|
taskGroup.GET("/api-key/:key", bind(api.TaskApi.RunTaskByKey, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
userGroup := apiGroup.Group("/user")
|
userGroup := apiGroup.Group("/user")
|
||||||
{
|
{
|
||||||
userGroup.POST("/login", bind(api.UserApi.LoginHandler, Body))
|
userGroup.POST("/login", bind(api.UserApi.LoginHandler, Body))
|
||||||
userGroup.POST("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.CreateUser, Body))
|
userGroup.POST("", middle.RolePermission(eum.RoleRoot), bind(api.UserApi.CreateUser, Body))
|
||||||
userGroup.PUT("/password", middle.RolePermission(constants.ROLE_USER), bind(api.UserApi.ChangePassword, Body))
|
userGroup.PUT("/password", middle.RolePermission(eum.RoleUser), bind(api.UserApi.ChangePassword, Body))
|
||||||
userGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.DeleteUser, Query))
|
userGroup.DELETE("", middle.RolePermission(eum.RoleRoot), bind(api.UserApi.DeleteUser, Query))
|
||||||
userGroup.GET("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.GetUserList, None))
|
userGroup.GET("", middle.RolePermission(eum.RoleRoot), bind(api.UserApi.GetUserList, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
pushGroup := apiGroup.Group("/push").Use(middle.RolePermission(constants.ROLE_ADMIN))
|
pushGroup := apiGroup.Group("/push").Use(middle.RolePermission(eum.RoleAdmin))
|
||||||
{
|
{
|
||||||
pushGroup.GET("/list", bind(api.PushApi.GetPushList, None))
|
pushGroup.GET("/list", bind(api.PushApi.GetPushList, None))
|
||||||
pushGroup.GET("", bind(api.PushApi.GetPushById, Query))
|
pushGroup.GET("", bind(api.PushApi.GetPushById, Query))
|
||||||
@@ -115,26 +115,26 @@ func routePathInit(r *gin.Engine) {
|
|||||||
pushGroup.DELETE("", bind(api.PushApi.DeletePushConfig, Query))
|
pushGroup.DELETE("", bind(api.PushApi.DeletePushConfig, Query))
|
||||||
}
|
}
|
||||||
|
|
||||||
fileGroup := apiGroup.Group("/file").Use(middle.RolePermission(constants.ROLE_ADMIN))
|
fileGroup := apiGroup.Group("/file").Use(middle.RolePermission(eum.RoleAdmin))
|
||||||
{
|
{
|
||||||
fileGroup.GET("/list", bind(api.FileApi.FilePathHandler, Query))
|
fileGroup.GET("/list", bind(api.FileApi.FilePathHandler, Query))
|
||||||
fileGroup.PUT("", bind(api.FileApi.FileWriteHandler, None))
|
fileGroup.PUT("", bind(api.FileApi.FileWriteHandler, None))
|
||||||
fileGroup.GET("", bind(api.FileApi.FileReadHandler, Query))
|
fileGroup.GET("", bind(api.FileApi.FileReadHandler, Query))
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionGroup := apiGroup.Group("/permission").Use(middle.RolePermission(constants.ROLE_ROOT))
|
permissionGroup := apiGroup.Group("/permission").Use(middle.RolePermission(eum.RoleRoot))
|
||||||
{
|
{
|
||||||
permissionGroup.GET("/list", bind(api.PermissionApi.GetPermissionList, Query))
|
permissionGroup.GET("/list", bind(api.PermissionApi.GetPermissionList, Query))
|
||||||
permissionGroup.PUT("", middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.PermissionApi.EditPermssion, Body))
|
permissionGroup.PUT("", middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.PermissionApi.EditPermssion, Body))
|
||||||
}
|
}
|
||||||
|
|
||||||
logGroup := apiGroup.Group("/log").Use(middle.RolePermission(constants.ROLE_USER))
|
logGroup := apiGroup.Group("/log").Use(middle.RolePermission(eum.RoleUser))
|
||||||
{
|
{
|
||||||
logGroup.POST("", bind(api.LogApi.GetLog, Body))
|
logGroup.POST("", bind(api.LogApi.GetLog, Body))
|
||||||
logGroup.GET("/running", bind(api.LogApi.GetRunningLog, None))
|
logGroup.GET("/running", bind(api.LogApi.GetRunningLog, None))
|
||||||
}
|
}
|
||||||
|
|
||||||
configGroup := apiGroup.Group("/config").Use(middle.RolePermission(constants.ROLE_ROOT))
|
configGroup := apiGroup.Group("/config").Use(middle.RolePermission(eum.RoleRoot))
|
||||||
{
|
{
|
||||||
configGroup.GET("", bind(api.ConfigApi.GetSystemConfiguration, None))
|
configGroup.GET("", bind(api.ConfigApi.GetSystemConfiguration, None))
|
||||||
configGroup.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None))
|
configGroup.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None))
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
package bleve
|
package bleve
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/blevesearch/bleve/v2"
|
"github.com/blevesearch/bleve/v2"
|
||||||
@@ -74,7 +73,6 @@ func (b *bleveSearch) Insert(logContent string, processName string, using string
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
logger.Logger.Warnw("bleve log insert failed", "err", err)
|
logger.Logger.Warnw("bleve log insert failed", "err", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("using: %v\n", using)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *bleveSearch) Search(req model.GetLogReq, filterProcessName ...string) (result model.LogResp) {
|
func (b *bleveSearch) Search(req model.GetLogReq, filterProcessName ...string) (result model.LogResp) {
|
||||||
|
@@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
||||||
"github.com/lzh-1625/go_process_manager/log"
|
"github.com/lzh-1625/go_process_manager/log"
|
||||||
"github.com/lzh-1625/go_process_manager/utils"
|
"github.com/lzh-1625/go_process_manager/utils"
|
||||||
@@ -49,7 +49,7 @@ func (t *tui) drawProcessList() {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
list.AddItem(v.Name, utils.NewKVStr().Add("user_name", v.User).Add("start_time", v.StartTime).Add("state", v.State.State).Build(), 'a'+rune(i), func() {
|
list.AddItem(v.Name, utils.NewKVStr().Add("user_name", v.User).Add("start_time", v.StartTime).Add("state", v.State.State).Build(), 'a'+rune(i), func() {
|
||||||
if v.State.State != 1 || v.TermType != constants.TERMINAL_PTY {
|
if v.State.State != 1 || v.TermType != eum.TerminalPty {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.teminal(v.Uuid)
|
t.teminal(v.Uuid)
|
||||||
@@ -75,8 +75,8 @@ func (t *tui) teminal(uuid int) {
|
|||||||
tci := &TermConnectInstance{
|
tci := &TermConnectInstance{
|
||||||
CancelFunc: cancel,
|
CancelFunc: cancel,
|
||||||
}
|
}
|
||||||
p.AddConn(constants.CONSOLE, tci)
|
p.AddConn(eum.Console, tci)
|
||||||
defer p.DeleteConn(constants.CONSOLE)
|
defer p.DeleteConn(eum.Console)
|
||||||
os.Stdin.Write([]byte("\033[H\033[2J")) // 清空屏幕
|
os.Stdin.Write([]byte("\033[H\033[2J")) // 清空屏幕
|
||||||
p.ReadCache(tci)
|
p.ReadCache(tci)
|
||||||
go t.startConnect(p, ctx, cancel)
|
go t.startConnect(p, ctx, cancel)
|
||||||
@@ -91,11 +91,11 @@ func (t *tui) teminal(uuid int) {
|
|||||||
|
|
||||||
func (t *tui) startConnect(p logic.Process, ctx context.Context, cancel context.CancelFunc) {
|
func (t *tui) startConnect(p logic.Process, ctx context.Context, cancel context.CancelFunc) {
|
||||||
switch p.Type() {
|
switch p.Type() {
|
||||||
case constants.TERMINAL_PTY:
|
case eum.TerminalPty:
|
||||||
{
|
{
|
||||||
t.ptyConnect(p, ctx, cancel)
|
t.ptyConnect(p, ctx, cancel)
|
||||||
}
|
}
|
||||||
case constants.TERMINAL_STD:
|
case eum.TerminalStd:
|
||||||
{
|
{
|
||||||
t.stdConnect(p, ctx, cancel)
|
t.stdConnect(p, ctx, cancel)
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/lzh-1625/go_process_manager/boot"
|
_ "github.com/lzh-1625/go_process_manager/boot"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
"github.com/lzh-1625/go_process_manager/internal/app/logic"
|
||||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ func TestCgroup(t *testing.T) {
|
|||||||
Name: "test",
|
Name: "test",
|
||||||
Cmd: "bash",
|
Cmd: "bash",
|
||||||
Cwd: `/root`,
|
Cwd: `/root`,
|
||||||
TermType: constants.TERMINAL_PTY,
|
TermType: eum.TerminalPty,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
6
resources/package-lock.json
generated
6
resources/package-lock.json
generated
@@ -1636,9 +1636,9 @@
|
|||||||
"url": "https://opencollective.com/popperjs"
|
"url": "https://opencollective.com/popperjs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@remirror/core-constants": {
|
"node_modules/@remirror/core-eum": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmmirror.com/@remirror/core-constants/-/core-constants-3.0.0.tgz",
|
"resolved": "https://registry.npmmirror.com/@remirror/core-eum/-/core-eum-3.0.0.tgz",
|
||||||
"integrity": "sha512-42aWfPrimMfDKDi4YegyS7x+/0tlzaqwPQCULLanv3DMIlu96KTJR0fM5isWX2UViOqlGnX6YFgqWepcX+XMNg==",
|
"integrity": "sha512-42aWfPrimMfDKDi4YegyS7x+/0tlzaqwPQCULLanv3DMIlu96KTJR0fM5isWX2UViOqlGnX6YFgqWepcX+XMNg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
@@ -5474,7 +5474,7 @@
|
|||||||
"integrity": "sha512-xiun5/3q0w5eRnGYfNlW1uU9W6x5MoFKWwq/0TIRgt09lv7Hcser2QYV8t4muXbEr+Fwo0geYn79Xs4GKywrRQ==",
|
"integrity": "sha512-xiun5/3q0w5eRnGYfNlW1uU9W6x5MoFKWwq/0TIRgt09lv7Hcser2QYV8t4muXbEr+Fwo0geYn79Xs4GKywrRQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@remirror/core-constants": "3.0.0",
|
"@remirror/core-eum": "3.0.0",
|
||||||
"escape-string-regexp": "^4.0.0"
|
"escape-string-regexp": "^4.0.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
Reference in New Issue
Block a user