mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-09-26 20:11:20 +08:00
Compare commits
5 Commits
1dc2d77e82
...
f723c12d42
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f723c12d42 | ||
![]() |
da54e71c27 | ||
![]() |
0d46bb7d07 | ||
![]() |
cffb1ee0f4 | ||
![]() |
143cf61a57 |
@@ -9,7 +9,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"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/middle"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
@@ -86,12 +86,12 @@ func initProcess() {
|
||||
}
|
||||
|
||||
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))
|
||||
return
|
||||
}
|
||||
secret := utils.RandString(32)
|
||||
repository.ConfigRepository.SetConfigValue(constants.SECRET_KEY, secret)
|
||||
repository.ConfigRepository.SetConfigValue(eum.SecretKey, secret)
|
||||
utils.SetSecret([]byte(secret))
|
||||
}
|
||||
|
||||
|
@@ -3,28 +3,28 @@ package api
|
||||
import (
|
||||
"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/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func getRole(ctx *gin.Context) constants.Role {
|
||||
if v, ok := ctx.Get(constants.CTXFLG_ROLE); ok {
|
||||
return v.(constants.Role)
|
||||
func getRole(ctx *gin.Context) eum.Role {
|
||||
if v, ok := ctx.Get(eum.CtxRole); ok {
|
||||
return v.(eum.Role)
|
||||
}
|
||||
return constants.ROLE_GUEST
|
||||
return eum.RoleGuest
|
||||
}
|
||||
|
||||
func getUserName(ctx *gin.Context) string {
|
||||
return ctx.GetString(constants.CTXFLG_USER_NAME)
|
||||
return ctx.GetString(eum.CtxUserName)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"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/model"
|
||||
"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) {
|
||||
return logic.LogLogicImpl.Search(req, req.FilterName...)
|
||||
} 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 {
|
||||
return !slices.Contains(processNameList, s)
|
||||
})
|
||||
|
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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/model"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
@@ -63,7 +64,7 @@ func (p *procApi) StartProcess(ctx *gin.Context, req struct {
|
||||
logic.ProcessCtlLogic.AddProcess(req.Uuid, proc)
|
||||
return nil
|
||||
}
|
||||
if prod.State.State == 1 {
|
||||
if prod.State.State == eum.ProcessStateStart || prod.State.State == eum.ProcessStateRunning {
|
||||
return errors.New("process is currently running")
|
||||
}
|
||||
prod.ResetRestartTimes()
|
||||
|
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"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/repository"
|
||||
"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) {
|
||||
if req.Role == constants.ROLE_ROOT {
|
||||
if req.Role == eum.RoleRoot {
|
||||
return errors.New("creation of root accounts is forbidden")
|
||||
}
|
||||
if req.Account == constants.CONSOLE {
|
||||
if req.Account == eum.Console {
|
||||
return errors.New("operation failed")
|
||||
}
|
||||
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) {
|
||||
reqUser := getUserName(ctx)
|
||||
if getRole(ctx) != constants.ROLE_ROOT && req.Account != "" {
|
||||
if getRole(ctx) != eum.RoleRoot && req.Account != "" {
|
||||
return errors.New("invalid parameters")
|
||||
}
|
||||
var userName string
|
||||
@@ -84,7 +84,7 @@ func (u *userApi) checkLoginInfo(account, password string) bool {
|
||||
repository.UserRepository.CreateUser(model.User{
|
||||
Account: "root",
|
||||
Password: DEFAULT_ROOT_PASSWORD,
|
||||
Role: constants.ROLE_ROOT,
|
||||
Role: eum.RoleRoot,
|
||||
})
|
||||
return password == DEFAULT_ROOT_PASSWORD
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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/model"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository"
|
||||
@@ -74,9 +74,9 @@ func (w *wsApi) WebsocketHandle(ctx *gin.Context, req model.WebsocketHandleReq)
|
||||
wsLock: sync.Mutex{},
|
||||
}
|
||||
proc.ReadCache(wci)
|
||||
if proc.State.State == 1 {
|
||||
if proc.State.State == eum.ProcessStateRunning {
|
||||
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)
|
||||
defer proc.DeleteConn(reqUser)
|
||||
}
|
||||
@@ -112,7 +112,7 @@ func (w *wsApi) WebsocketShareHandle(ctx *gin.Context, req model.WebsocketHandle
|
||||
if proc.HasWsConn(guestName) {
|
||||
return errors.New("connection already exists")
|
||||
}
|
||||
if proc.State.State != 1 {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
return errors.New("process not is running")
|
||||
}
|
||||
if !proc.VerifyControl() {
|
||||
|
@@ -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"
|
||||
)
|
17
internal/app/eum/process.go
Normal file
17
internal/app/eum/process.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package eum
|
||||
|
||||
type TerminalType string
|
||||
|
||||
const (
|
||||
TerminalPty TerminalType = "pty"
|
||||
TerminalStd TerminalType = "std"
|
||||
)
|
||||
|
||||
type ProcessState int32
|
||||
|
||||
const (
|
||||
ProcessStateStop ProcessState = iota
|
||||
ProcessStateStart
|
||||
ProcessStateWarnning
|
||||
ProcessStateRunning
|
||||
)
|
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{}
|
32
internal/app/logic/event.go
Normal file
32
internal/app/logic/event.go
Normal file
@@ -0,0 +1,32 @@
|
||||
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) {
|
||||
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]
|
||||
}
|
||||
if err := repository.EventRepository.Create(data); err != nil {
|
||||
log.Logger.Errorw("事件创建失败", "err", err)
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -10,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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/model"
|
||||
"github.com/lzh-1625/go_process_manager/log"
|
||||
@@ -27,7 +28,7 @@ type Process interface {
|
||||
doOnInit()
|
||||
doOnKilled()
|
||||
Start() error
|
||||
Type() constants.TerminalType
|
||||
Type() eum.TerminalType
|
||||
SetTerminalSize(int, int)
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ type ProcessBase struct {
|
||||
State struct {
|
||||
startTime time.Time
|
||||
Info string
|
||||
State constants.ProcessState //0 为未运行,1为运作中,2为异常状态
|
||||
State eum.ProcessState //0 为未运行,1为运作中,2为异常状态
|
||||
stateLock sync.Mutex
|
||||
restartTimes int
|
||||
manualStopFlag bool
|
||||
@@ -93,7 +94,7 @@ func (p *ProcessBase) watchDog() {
|
||||
}
|
||||
close(p.StopChan)
|
||||
p.doOnKilled()
|
||||
p.SetState(constants.PROCESS_STOP)
|
||||
p.SetState(eum.ProcessStateStop)
|
||||
if state.ExitCode() != 0 {
|
||||
log.Logger.Infow("进程停止", "进程名称", p.Name, "exitCode", state.ExitCode(), "进程类型", p.Type())
|
||||
p.push(fmt.Sprintf("进程停止,退出码 %d", state.ExitCode()))
|
||||
@@ -117,7 +118,7 @@ func (p *ProcessBase) watchDog() {
|
||||
return
|
||||
}
|
||||
log.Logger.Warnw("重启次数达到上限", "name", p.Name, "limit", config.CF.ProcessRestartsLimit)
|
||||
p.SetState(constants.PROCESS_WARNNING)
|
||||
p.SetState(eum.ProcessStateWarnning)
|
||||
p.State.Info = "重启次数异常"
|
||||
p.push("进程重启次数达到上限")
|
||||
}
|
||||
@@ -139,7 +140,7 @@ func (p *ProcessBase) pInit() {
|
||||
}
|
||||
|
||||
// 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()
|
||||
defer p.State.stateLock.Unlock()
|
||||
for _, v := range fn {
|
||||
@@ -149,10 +150,24 @@ func (p *ProcessBase) SetState(state constants.ProcessState, fn ...func() bool)
|
||||
}
|
||||
p.State.State = state
|
||||
middle.ProcessWaitCond.Trigger()
|
||||
p.createEvent(state)
|
||||
go TaskLogic.RunTaskByTriggerEvent(p.Name, state)
|
||||
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 {
|
||||
return strings.Join(p.GetUserList(), ";")
|
||||
}
|
||||
@@ -267,7 +282,7 @@ func (p *ProcessBase) monitorHanler() {
|
||||
ticker := time.NewTicker(time.Second * time.Duration(config.CF.PerformanceInfoInterval))
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
if p.State.State != 1 {
|
||||
if p.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "state", p.State.State)
|
||||
return
|
||||
}
|
||||
@@ -306,6 +321,10 @@ func (p *ProcessBase) initPsutil() {
|
||||
}
|
||||
|
||||
func (p *ProcessBase) Kill() error {
|
||||
if p.State.State != eum.ProcessStateRunning {
|
||||
return errors.New("can't kill not running process")
|
||||
}
|
||||
p.State.manualStopFlag = true
|
||||
p.op.Signal(syscall.SIGINT)
|
||||
select {
|
||||
case <-p.StopChan:
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"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/repository"
|
||||
"github.com/lzh-1625/go_process_manager/log"
|
||||
@@ -37,10 +37,6 @@ func (p *processCtlLogic) KillProcess(uuid int) error {
|
||||
if !ok {
|
||||
return errors.New("进程类型错误")
|
||||
}
|
||||
if result.State.State != 1 {
|
||||
return nil
|
||||
}
|
||||
result.State.manualStopFlag = true
|
||||
return result.Kill()
|
||||
}
|
||||
|
||||
@@ -61,13 +57,9 @@ func (p *processCtlLogic) KillAllProcess() {
|
||||
wg := sync.WaitGroup{}
|
||||
p.processMap.Range(func(key, value any) bool {
|
||||
process := value.(*ProcessBase)
|
||||
if process.State.State != 1 {
|
||||
return true
|
||||
}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
process.State.manualStopFlag = true
|
||||
process.Kill()
|
||||
}()
|
||||
return true
|
||||
@@ -76,7 +68,7 @@ func (p *processCtlLogic) KillAllProcess() {
|
||||
}
|
||||
|
||||
func (p *processCtlLogic) KillAllProcessByUserName(userName string) {
|
||||
stopPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, constants.OPERATION_STOP)
|
||||
stopPermissionProcess := repository.PermissionRepository.GetProcessNameByPermission(userName, eum.OperationStop)
|
||||
wg := sync.WaitGroup{}
|
||||
p.processMap.Range(func(key, value any) bool {
|
||||
process := value.(*ProcessBase)
|
||||
@@ -183,7 +175,7 @@ func (p *processCtlLogic) ProcessInit() {
|
||||
}
|
||||
|
||||
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 {
|
||||
process := value.(*ProcessBase)
|
||||
if !slices.Contains(startPermissionProcess, process.Name) {
|
||||
@@ -225,9 +217,9 @@ func (p *processCtlLogic) UpdateProcessConfig(config model.Process) error {
|
||||
|
||||
func (p *processCtlLogic) NewProcess(config model.Process) (proc *ProcessBase, err error) {
|
||||
switch config.TermType {
|
||||
case constants.TERMINAL_STD:
|
||||
case eum.TerminalStd:
|
||||
proc = NewProcessStd(config)
|
||||
case constants.TERMINAL_PTY:
|
||||
case eum.TerminalPty:
|
||||
proc = NewProcessPty(config)
|
||||
default:
|
||||
err = errors.New("终端类型错误")
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/google/shlex"
|
||||
"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/log"
|
||||
"github.com/lzh-1625/go_process_manager/utils"
|
||||
@@ -26,20 +26,20 @@ func (p *ProcessPty) doOnKilled() {
|
||||
p.pty.Close()
|
||||
}
|
||||
|
||||
func (p *ProcessPty) Type() constants.TerminalType {
|
||||
return constants.TERMINAL_PTY
|
||||
func (p *ProcessPty) Type() eum.TerminalType {
|
||||
return eum.TerminalPty
|
||||
}
|
||||
|
||||
func (p *ProcessPty) Start() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
p.Config.AutoRestart = false
|
||||
p.SetState(constants.PROCESS_WARNNING)
|
||||
p.SetState(eum.ProcessStateWarnning)
|
||||
p.State.Info = "进程启动失败:" + err.Error()
|
||||
}
|
||||
}()
|
||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
||||
return p.State.State != 1
|
||||
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||
return p.State.State != eum.ProcessStateStart
|
||||
}); !ok {
|
||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||
return nil
|
||||
|
@@ -2,11 +2,12 @@ package logic
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"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/log"
|
||||
"github.com/lzh-1625/go_process_manager/utils"
|
||||
@@ -24,20 +25,20 @@ func (p *ProcessPty) doOnKilled() {
|
||||
p.pty.Close()
|
||||
}
|
||||
|
||||
func (p *ProcessPty) Type() constants.TerminalType {
|
||||
return constants.TERMINAL_PTY
|
||||
func (p *ProcessPty) Type() eum.TerminalType {
|
||||
return eum.TerminalPty
|
||||
}
|
||||
|
||||
func (p *ProcessPty) Start() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
p.Config.AutoRestart = false
|
||||
p.SetState(constants.PROCESS_WARNNING)
|
||||
p.SetState(eum.ProcessStateWarnning)
|
||||
p.State.Info = "进程启动失败:" + err.Error()
|
||||
}
|
||||
}()
|
||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
||||
return p.State.State != 1
|
||||
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||
return p.State.State != eum.ProcessStateRunning && p.State.State != eum.ProcessStateStart
|
||||
}); !ok {
|
||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||
return nil
|
||||
@@ -66,6 +67,11 @@ func (p *ProcessPty) Start() (err error) {
|
||||
}
|
||||
log.Logger.Infow("进程启动成功", "进程名称", p.Name, "重启次数", p.State.restartTimes)
|
||||
p.pInit()
|
||||
if !p.SetState(eum.ProcessStateRunning, func() bool {
|
||||
return p.State.State == eum.ProcessStateStart
|
||||
}) {
|
||||
return errors.New("状态异常启动失败")
|
||||
}
|
||||
p.push("进程启动成功")
|
||||
return nil
|
||||
}
|
||||
|
@@ -2,13 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"os/exec"
|
||||
|
||||
"github.com/google/shlex"
|
||||
|
||||
"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/log"
|
||||
"github.com/lzh-1625/go_process_manager/utils"
|
||||
@@ -21,8 +22,8 @@ type ProcessStd struct {
|
||||
stdout *bufio.Scanner
|
||||
}
|
||||
|
||||
func (p *ProcessStd) Type() constants.TerminalType {
|
||||
return constants.TERMINAL_STD
|
||||
func (p *ProcessStd) Type() eum.TerminalType {
|
||||
return eum.TerminalStd
|
||||
}
|
||||
|
||||
func (p *ProcessStd) WriteBytes(input []byte) (err error) {
|
||||
@@ -41,12 +42,12 @@ func (p *ProcessStd) Start() (err error) {
|
||||
defer func() {
|
||||
if err != nil {
|
||||
p.Config.AutoRestart = false
|
||||
p.SetState(constants.PROCESS_WARNNING)
|
||||
p.SetState(eum.ProcessStateWarnning)
|
||||
p.State.Info = "进程启动失败:" + err.Error()
|
||||
}
|
||||
}()
|
||||
if ok := p.SetState(constants.PROCESS_START, func() bool {
|
||||
return p.State.State != 1
|
||||
if ok := p.SetState(eum.ProcessStateStart, func() bool {
|
||||
return p.State.State != eum.ProcessStateRunning && p.State.State != eum.ProcessStateStart
|
||||
}); !ok {
|
||||
log.Logger.Warnw("进程已在运行,跳过启动")
|
||||
return nil
|
||||
@@ -73,6 +74,11 @@ func (p *ProcessStd) Start() (err error) {
|
||||
log.Logger.Infow("进程启动成功", "重启次数", p.State.restartTimes)
|
||||
p.op = cmd.Process
|
||||
p.pInit()
|
||||
if !p.SetState(eum.ProcessStateRunning, func() bool {
|
||||
return p.State.State == eum.ProcessStateStart
|
||||
}) {
|
||||
return errors.New("状态异常启动失败")
|
||||
}
|
||||
p.push("进程启动成功")
|
||||
return nil
|
||||
}
|
||||
|
@@ -4,7 +4,8 @@ import (
|
||||
"context"
|
||||
"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/model"
|
||||
"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) {
|
||||
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
|
||||
middle.TaskWaitCond.Trigger()
|
||||
defer func() {
|
||||
@@ -43,7 +48,7 @@ func (t *TaskJob) Run(ctx context.Context) {
|
||||
}()
|
||||
var ok bool
|
||||
// 判断条件是否满足
|
||||
if t.TaskConfig.Condition == constants.PASS {
|
||||
if t.TaskConfig.Condition == eum.TaskCondPass {
|
||||
ok = true
|
||||
} else {
|
||||
proc, err := ProcessCtlLogic.GetProcess(t.TaskConfig.OperationTarget)
|
||||
@@ -91,6 +96,7 @@ func (t *TaskJob) Run(ctx context.Context) {
|
||||
} else {
|
||||
log.Logger.Infow("任务流结束")
|
||||
}
|
||||
EventLogic.Create(t.TaskConfig.Name, eum.EventProcessStop, "traceId", ctx.Value(eum.CtxTaskTraceId{}))
|
||||
}
|
||||
|
||||
func (t *TaskJob) InitCronHandle() error {
|
||||
|
@@ -4,50 +4,50 @@ import (
|
||||
"time"
|
||||
|
||||
"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/log"
|
||||
)
|
||||
|
||||
type conditionFunc func(data *model.Task, proc *ProcessBase) bool
|
||||
|
||||
var conditionHandle = map[constants.Condition]conditionFunc{
|
||||
constants.RUNNING: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == 1
|
||||
var conditionHandle = map[eum.Condition]conditionFunc{
|
||||
eum.TaskCondRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == eum.ProcessStateRunning
|
||||
},
|
||||
constants.NOT_RUNNING: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State != 1
|
||||
eum.TaskCondNotRunning: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State != eum.ProcessStateRunning && proc.State.State != eum.ProcessStateStart
|
||||
},
|
||||
constants.EXCEPTION: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == 2
|
||||
eum.TaskCondException: func(data *model.Task, proc *ProcessBase) bool {
|
||||
return proc.State.State == eum.ProcessStateWarnning
|
||||
},
|
||||
}
|
||||
|
||||
// 执行操作,返回结果是否成功
|
||||
type operationFunc func(data *model.Task, proc *ProcessBase) bool
|
||||
|
||||
var OperationHandle = map[constants.TaskOperation]operationFunc{
|
||||
constants.TASK_START: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == 1 {
|
||||
log.Logger.Debugw("进程已在运行")
|
||||
var OperationHandle = map[eum.TaskOperation]operationFunc{
|
||||
eum.TaskStart: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == eum.ProcessStateRunning || proc.State.State == eum.ProcessStateStart {
|
||||
log.Logger.Debugw("进程已在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
go proc.Start()
|
||||
proc.Start()
|
||||
return true
|
||||
},
|
||||
|
||||
constants.TASK_START_WAIT_DONE: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == 1 {
|
||||
log.Logger.Debugw("进程已在运行")
|
||||
eum.TaskStartWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State == eum.ProcessStateRunning || proc.State.State == eum.ProcessStateStart {
|
||||
log.Logger.Debugw("进程已在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
if err := proc.Start(); err != nil {
|
||||
log.Logger.Debugw("进程启动失败")
|
||||
log.Logger.Debugw("进程启动失败", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
select {
|
||||
case <-proc.StopChan:
|
||||
log.Logger.Debugw("进程停止,任务完成")
|
||||
log.Logger.Debugw("进程停止,任务完成", "proc", proc.Name)
|
||||
return true
|
||||
case <-time.After(time.Second * time.Duration(config.CF.TaskTimeout)):
|
||||
log.Logger.Errorw("任务超时")
|
||||
@@ -55,24 +55,22 @@ var OperationHandle = map[constants.TaskOperation]operationFunc{
|
||||
}
|
||||
},
|
||||
|
||||
constants.TASK_STOP: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != 1 {
|
||||
log.Logger.Debugw("进程未在运行")
|
||||
eum.TaskStop: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
log.Logger.Debugw("异步停止任务")
|
||||
proc.State.manualStopFlag = true
|
||||
log.Logger.Debugw("异步停止任务", "proc", proc.Name)
|
||||
go proc.Kill()
|
||||
return true
|
||||
},
|
||||
|
||||
constants.TASK_STOP_WAIT_DONE: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != 1 {
|
||||
log.Logger.Debugw("进程未在运行")
|
||||
eum.TaskStopWaitDone: func(data *model.Task, proc *ProcessBase) bool {
|
||||
if proc.State.State != eum.ProcessStateRunning {
|
||||
log.Logger.Debugw("进程未在运行", "proc", proc.Name)
|
||||
return false
|
||||
}
|
||||
log.Logger.Debugw("停止任务并等待结束")
|
||||
proc.State.manualStopFlag = true
|
||||
log.Logger.Debugw("停止任务并等待结束", "proc", proc.Name)
|
||||
return proc.Kill() == nil
|
||||
},
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"errors"
|
||||
"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/repository"
|
||||
"github.com/lzh-1625/go_process_manager/log"
|
||||
@@ -154,7 +154,7 @@ func (t *taskLogic) RunTaskByKey(key string) error {
|
||||
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)
|
||||
if len(taskList) == 0 {
|
||||
return
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@@ -25,7 +25,7 @@ func Logger() gin.HandlerFunc {
|
||||
logKv = append(logKv, "Status", ctx.Writer.Status())
|
||||
logKv = append(logKv, "Path", path)
|
||||
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)
|
||||
}
|
||||
switch {
|
||||
|
@@ -4,15 +4,15 @@ import (
|
||||
"reflect"
|
||||
"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/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) {
|
||||
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)
|
||||
ctx.Abort()
|
||||
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) {
|
||||
uuid, err := strconv.Atoi(ctx.Query("uuid"))
|
||||
if err != nil {
|
||||
@@ -29,11 +29,11 @@ func OprPermission(op constants.OprPermission) func(ctx *gin.Context) {
|
||||
ctx.Abort()
|
||||
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()
|
||||
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)
|
||||
ctx.Abort()
|
||||
return
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"slices"
|
||||
"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/log"
|
||||
"github.com/lzh-1625/go_process_manager/utils"
|
||||
@@ -58,8 +58,8 @@ func CheckToken() gin.HandlerFunc {
|
||||
if username, err := getUser(c); err != nil {
|
||||
rErr(c, -1, "无法获取user信息", err)
|
||||
} else {
|
||||
c.Set(constants.CTXFLG_USER_NAME, username)
|
||||
c.Set(constants.CTXFLG_ROLE, repository.UserRepository.GetUserByName(username).Role)
|
||||
c.Set(eum.CtxUserName, username)
|
||||
c.Set(eum.CtxRole, repository.UserRepository.GetUserByName(username).Role)
|
||||
}
|
||||
}
|
||||
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,18 +1,18 @@
|
||||
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 {
|
||||
Name string `json:"name"`
|
||||
Uuid int `json:"uuid"`
|
||||
StartTime string `json:"startTime"`
|
||||
User string `json:"user"`
|
||||
Usage Usage `json:"usage"`
|
||||
State State `json:"state"`
|
||||
TermType constants.TerminalType `json:"termType"`
|
||||
CgroupEnable bool `json:"cgroupEnable"`
|
||||
MemoryLimit *float32 `json:"memoryLimit"`
|
||||
CpuLimit *float32 `json:"cpuLimit"`
|
||||
Name string `json:"name"`
|
||||
Uuid int `json:"uuid"`
|
||||
StartTime string `json:"startTime"`
|
||||
User string `json:"user"`
|
||||
Usage Usage `json:"usage"`
|
||||
State State `json:"state"`
|
||||
TermType eum.TerminalType `json:"termType"`
|
||||
CgroupEnable bool `json:"cgroupEnable"`
|
||||
MemoryLimit *float32 `json:"memoryLimit"`
|
||||
CpuLimit *float32 `json:"cpuLimit"`
|
||||
}
|
||||
|
||||
type Usage struct {
|
||||
@@ -24,6 +24,6 @@ type Usage struct {
|
||||
}
|
||||
|
||||
type State struct {
|
||||
State constants.ProcessState `json:"state"`
|
||||
Info string `json:"info"`
|
||||
State eum.ProcessState `json:"state"`
|
||||
Info string `json:"info"`
|
||||
}
|
||||
|
@@ -1,20 +1,20 @@
|
||||
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 {
|
||||
Uuid int `gorm:"primaryKey;autoIncrement;column:uuid" json:"uuid"`
|
||||
Name string `gorm:"column:name;uniqueIndex;type:text" json:"name" binding:"required"`
|
||||
Cmd string `gorm:"column:args" json:"cmd"`
|
||||
Cwd string `gorm:"column:cwd" json:"cwd"`
|
||||
AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"`
|
||||
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"`
|
||||
PushIds string `gorm:"column:push_ids" json:"pushIds"`
|
||||
LogReport bool `gorm:"column:log_report" json:"logReport"`
|
||||
TermType constants.TerminalType `gorm:"column:term_type" json:"termType"`
|
||||
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`
|
||||
MemoryLimit *float32 `gorm:"column:memory_limit" json:"memoryLimit"`
|
||||
CpuLimit *float32 `gorm:"column:cpu_limit" json:"cpuLimit"`
|
||||
Uuid int `gorm:"primaryKey;autoIncrement;column:uuid" json:"uuid"`
|
||||
Name string `gorm:"column:name;uniqueIndex;type:text" json:"name" binding:"required"`
|
||||
Cmd string `gorm:"column:args" json:"cmd"`
|
||||
Cwd string `gorm:"column:cwd" json:"cwd"`
|
||||
AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"`
|
||||
CompulsoryRestart bool `gorm:"column:compulsory_restart" json:"compulsoryRestart"`
|
||||
PushIds string `gorm:"column:push_ids" json:"pushIds"`
|
||||
LogReport bool `gorm:"column:log_report" json:"logReport"`
|
||||
TermType eum.TerminalType `gorm:"column:term_type" json:"termType"`
|
||||
CgroupEnable bool `gorm:"column:cgroup_enable" json:"cgroupEnable"`
|
||||
MemoryLimit *float32 `gorm:"column:memory_limit" json:"memoryLimit"`
|
||||
CpuLimit *float32 `gorm:"column:cpu_limit" json:"cpuLimit"`
|
||||
}
|
||||
|
||||
func (*Process) TableName() string {
|
||||
|
@@ -3,22 +3,23 @@ package model
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||
)
|
||||
|
||||
type Task struct {
|
||||
Id int `gorm:"column:id;NOT NULL;primaryKey;autoIncrement;" json:"id" `
|
||||
ProcessId int `gorm:"column:process_id;NOT NULL" json:"processId" `
|
||||
Condition constants.Condition `gorm:"column:condition;NOT NULL" json:"condition" `
|
||||
NextId *int `gorm:"column:next_id;" json:"nextId" `
|
||||
Operation constants.TaskOperation `gorm:"column:operation;NOT NULL" json:"operation" `
|
||||
TriggerEvent *constants.ProcessState `gorm:"column:trigger_event;" json:"triggerEvent" `
|
||||
TriggerTarget *int `gorm:"column:trigger_target;" json:"triggerTarget" `
|
||||
OperationTarget int `gorm:"column:operation_target;NOT NULL" json:"operationTarget" `
|
||||
CronExpression string `gorm:"column:cron;" json:"cron" `
|
||||
Enable bool `gorm:"column:enable;" json:"enable" `
|
||||
ApiEnable bool `gorm:"column:api_enable;" json:"apiEnable" `
|
||||
Key *string `gorm:"column:key;" json:"key" `
|
||||
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" `
|
||||
Condition eum.Condition `gorm:"column:condition;NOT NULL" json:"condition" `
|
||||
NextId *int `gorm:"column:next_id;" json:"nextId" `
|
||||
Operation eum.TaskOperation `gorm:"column:operation;NOT NULL" json:"operation" `
|
||||
TriggerEvent *eum.ProcessState `gorm:"column:trigger_event;" json:"triggerEvent" `
|
||||
TriggerTarget *int `gorm:"column:trigger_target;" json:"triggerTarget" `
|
||||
OperationTarget int `gorm:"column:operation_target;NOT NULL" json:"operationTarget" `
|
||||
CronExpression string `gorm:"column:cron;" json:"cron" `
|
||||
Enable bool `gorm:"column:enable;" json:"enable" `
|
||||
ApiEnable bool `gorm:"column:api_enable;" json:"apiEnable" `
|
||||
Key *string `gorm:"column:key;" json:"key" `
|
||||
}
|
||||
|
||||
func (*Task) TableName() string {
|
||||
|
@@ -3,15 +3,15 @@ package model
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/eum"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Account string `json:"account" gorm:"primaryKey;column:account" `
|
||||
Password string `json:"password" gorm:"column:password" `
|
||||
Role constants.Role `json:"role" gorm:"column:role" `
|
||||
CreateTime time.Time `json:"createTime" gorm:"column:create_time" `
|
||||
Remark string `json:"remark" gorm:"column:remark" `
|
||||
Account string `json:"account" gorm:"primaryKey;column:account" `
|
||||
Password string `json:"password" gorm:"column:password" `
|
||||
Role eum.Role `json:"role" gorm:"column:role" `
|
||||
CreateTime time.Time `json:"createTime" gorm:"column:create_time" `
|
||||
Remark string `json:"remark" gorm:"column:remark" `
|
||||
}
|
||||
|
||||
func (*User) TableName() string {
|
||||
|
@@ -42,14 +42,17 @@ func InitDb() {
|
||||
sqlDB.SetConnMaxLifetime(time.Hour)
|
||||
db = gdb.Session(&defaultConfig)
|
||||
// db = db.Debug()
|
||||
db.AutoMigrate(&model.Process{}, &model.User{}, &model.Permission{}, &model.Push{}, &model.Config{}, &model.ProcessLog{}, &model.Task{}, &model.WsShare{})
|
||||
|
||||
// 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{})
|
||||
// g.Execute()
|
||||
db.AutoMigrate(
|
||||
&model.Process{},
|
||||
&model.User{},
|
||||
&model.Permission{},
|
||||
&model.Push{},
|
||||
&model.Config{},
|
||||
&model.ProcessLog{},
|
||||
&model.Task{},
|
||||
&model.WsShare{},
|
||||
&model.Event{},
|
||||
)
|
||||
gormGen(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 (
|
||||
"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/repository/query"
|
||||
"github.com/lzh-1625/go_process_manager/log"
|
||||
@@ -64,18 +64,18 @@ func (p *permissionRepository) GetPermission(user string, pid int) (result model
|
||||
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))
|
||||
switch op {
|
||||
case constants.OPERATION_LOG:
|
||||
case eum.OperationLog:
|
||||
tx = tx.Where(query.Permission.Log.Is(true))
|
||||
case constants.OPERATION_START:
|
||||
case eum.OperationStart:
|
||||
tx = tx.Where(query.Permission.Start.Is(true))
|
||||
case constants.OPERATION_STOP:
|
||||
case eum.OperationStop:
|
||||
tx = tx.Where(query.Permission.Stop.Is(true))
|
||||
case constants.OPERATION_TERMINAL:
|
||||
case eum.OperationTerminal:
|
||||
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.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 (
|
||||
Q = new(Query)
|
||||
Config *config
|
||||
Event *event
|
||||
Permission *permission
|
||||
Process *process
|
||||
ProcessLog *processLog
|
||||
@@ -30,6 +31,7 @@ var (
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
Config = &Q.Config
|
||||
Event = &Q.Event
|
||||
Permission = &Q.Permission
|
||||
Process = &Q.Process
|
||||
ProcessLog = &Q.ProcessLog
|
||||
@@ -43,6 +45,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Config: newConfig(db, opts...),
|
||||
Event: newEvent(db, opts...),
|
||||
Permission: newPermission(db, opts...),
|
||||
Process: newProcess(db, opts...),
|
||||
ProcessLog: newProcessLog(db, opts...),
|
||||
@@ -57,6 +60,7 @@ type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Config config
|
||||
Event event
|
||||
Permission permission
|
||||
Process process
|
||||
ProcessLog processLog
|
||||
@@ -72,6 +76,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Config: q.Config.clone(db),
|
||||
Event: q.Event.clone(db),
|
||||
Permission: q.Permission.clone(db),
|
||||
Process: q.Process.clone(db),
|
||||
ProcessLog: q.ProcessLog.clone(db),
|
||||
@@ -94,6 +99,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Config: q.Config.replaceDB(db),
|
||||
Event: q.Event.replaceDB(db),
|
||||
Permission: q.Permission.replaceDB(db),
|
||||
Process: q.Process.replaceDB(db),
|
||||
ProcessLog: q.ProcessLog.replaceDB(db),
|
||||
@@ -106,6 +112,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
|
||||
type queryCtx struct {
|
||||
Config IConfigDo
|
||||
Event IEventDo
|
||||
Permission IPermissionDo
|
||||
Process IProcessDo
|
||||
ProcessLog IProcessLogDo
|
||||
@@ -118,6 +125,7 @@ type queryCtx struct {
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Config: q.Config.WithContext(ctx),
|
||||
Event: q.Event.WithContext(ctx),
|
||||
Permission: q.Permission.WithContext(ctx),
|
||||
Process: q.Process.WithContext(ctx),
|
||||
ProcessLog: q.ProcessLog.WithContext(ctx),
|
||||
|
@@ -28,6 +28,7 @@ func newTask(db *gorm.DB, opts ...gen.DOOption) task {
|
||||
tableName := _task.taskDo.TableName()
|
||||
_task.ALL = field.NewAsterisk(tableName)
|
||||
_task.Id = field.NewInt(tableName, "id")
|
||||
_task.Name = field.NewString(tableName, "name")
|
||||
_task.ProcessId = field.NewInt(tableName, "process_id")
|
||||
_task.Condition = field.NewInt(tableName, "condition")
|
||||
_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.TriggerTarget = field.NewInt(tableName, "trigger_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.ApiEnable = field.NewBool(tableName, "api_enable")
|
||||
_task.Key = field.NewString(tableName, "key")
|
||||
@@ -50,6 +51,7 @@ type task struct {
|
||||
|
||||
ALL field.Asterisk
|
||||
Id field.Int
|
||||
Name field.String
|
||||
ProcessId field.Int
|
||||
Condition field.Int
|
||||
NextId field.Int
|
||||
@@ -57,7 +59,7 @@ type task struct {
|
||||
TriggerEvent field.Int32
|
||||
TriggerTarget field.Int
|
||||
OperationTarget field.Int
|
||||
Cron field.String
|
||||
CronExpression field.String
|
||||
Enable field.Bool
|
||||
ApiEnable field.Bool
|
||||
Key field.String
|
||||
@@ -78,6 +80,7 @@ func (t task) As(alias string) *task {
|
||||
func (t *task) updateTableName(table string) *task {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.Id = field.NewInt(table, "id")
|
||||
t.Name = field.NewString(table, "name")
|
||||
t.ProcessId = field.NewInt(table, "process_id")
|
||||
t.Condition = field.NewInt(table, "condition")
|
||||
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.TriggerTarget = field.NewInt(table, "trigger_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.ApiEnable = field.NewBool(table, "api_enable")
|
||||
t.Key = field.NewString(table, "key")
|
||||
@@ -105,8 +108,9 @@ func (t *task) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
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["name"] = t.Name
|
||||
t.fieldMap["process_id"] = t.ProcessId
|
||||
t.fieldMap["condition"] = t.Condition
|
||||
t.fieldMap["next_id"] = t.NextId
|
||||
@@ -114,7 +118,7 @@ func (t *task) fillFieldMap() {
|
||||
t.fieldMap["trigger_event"] = t.TriggerEvent
|
||||
t.fieldMap["trigger_target"] = t.TriggerTarget
|
||||
t.fieldMap["operation_target"] = t.OperationTarget
|
||||
t.fieldMap["cron"] = t.Cron
|
||||
t.fieldMap["cron"] = t.CronExpression
|
||||
t.fieldMap["enable"] = t.Enable
|
||||
t.fieldMap["api_enable"] = t.ApiEnable
|
||||
t.fieldMap["key"] = t.Key
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package repository
|
||||
|
||||
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/repository/query"
|
||||
)
|
||||
@@ -64,7 +64,7 @@ func (t *taskRepository) GetAllTaskWithProcessName() (result []model.TaskVo) {
|
||||
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{}
|
||||
query.Task.Select(query.Task.ALL).
|
||||
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/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/log"
|
||||
"github.com/lzh-1625/go_process_manager/resources"
|
||||
@@ -58,55 +58,55 @@ func routePathInit(r *gin.Engine) {
|
||||
{
|
||||
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))
|
||||
}
|
||||
|
||||
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("/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.DELETE("/all", bind(api.ProcApi.KillAllProcess, None))
|
||||
processGroup.POST("/share", middle.RolePermission(constants.ROLE_ADMIN), bind(api.ProcApi.ProcessCreateShare, Body))
|
||||
processGroup.GET("/control", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.ProcessControl, Query))
|
||||
processGroup.POST("/share", middle.RolePermission(eum.RoleAdmin), bind(api.ProcApi.ProcessCreateShare, Body))
|
||||
processGroup.GET("/control", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.ProcessControl, Query))
|
||||
|
||||
proConfigGroup := processGroup.Group("/config")
|
||||
{
|
||||
proConfigGroup.POST("", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.CreateNewProcess, Body))
|
||||
proConfigGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.DeleteNewProcess, Query))
|
||||
proConfigGroup.PUT("", middle.RolePermission(constants.ROLE_ROOT), bind(api.ProcApi.UpdateProcessConfig, Body))
|
||||
proConfigGroup.GET("", middle.RolePermission(constants.ROLE_ADMIN), bind(api.ProcApi.GetProcessConfig, Query))
|
||||
proConfigGroup.POST("", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.CreateNewProcess, Body))
|
||||
proConfigGroup.DELETE("", middle.RolePermission(eum.RoleRoot), middle.ProcessWaitCond.WaitTriggerMiddel, bind(api.ProcApi.DeleteNewProcess, Query))
|
||||
proConfigGroup.PUT("", middle.RolePermission(eum.RoleRoot), bind(api.ProcApi.UpdateProcessConfig, Body))
|
||||
proConfigGroup.GET("", middle.RolePermission(eum.RoleAdmin), bind(api.ProcApi.GetProcessConfig, Query))
|
||||
}
|
||||
}
|
||||
|
||||
taskGroup := apiGroup.Group("/task")
|
||||
{
|
||||
taskGroup.GET("", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.GetTaskById, Query))
|
||||
taskGroup.GET("/all", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.GetTaskList, None))
|
||||
taskGroup.GET("/all/wait", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitGetMiddel, bind(api.TaskApi.GetTaskList, None))
|
||||
taskGroup.POST("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.CreateTask, Body))
|
||||
taskGroup.DELETE("", middle.RolePermission(constants.ROLE_ADMIN), 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("/enable", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTaskEnable, Body))
|
||||
taskGroup.GET("/start", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.StartTask, Query))
|
||||
taskGroup.GET("/stop", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.StopTask, Query))
|
||||
taskGroup.POST("/key", middle.RolePermission(constants.ROLE_ADMIN), bind(api.TaskApi.CreateTaskApiKey, Body))
|
||||
taskGroup.GET("", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.GetTaskById, Query))
|
||||
taskGroup.GET("/all", middle.RolePermission(eum.RoleAdmin), 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(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.CreateTask, Body))
|
||||
taskGroup.DELETE("", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.DeleteTaskById, Query))
|
||||
taskGroup.PUT("", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTask, Body))
|
||||
taskGroup.PUT("/enable", middle.RolePermission(eum.RoleAdmin), middle.TaskWaitCond.WaitTriggerMiddel, bind(api.TaskApi.EditTaskEnable, Body))
|
||||
taskGroup.GET("/start", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.StartTask, Query))
|
||||
taskGroup.GET("/stop", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.StopTask, Query))
|
||||
taskGroup.POST("/key", middle.RolePermission(eum.RoleAdmin), bind(api.TaskApi.CreateTaskApiKey, Body))
|
||||
taskGroup.GET("/api-key/:key", bind(api.TaskApi.RunTaskByKey, None))
|
||||
}
|
||||
|
||||
userGroup := apiGroup.Group("/user")
|
||||
{
|
||||
userGroup.POST("/login", bind(api.UserApi.LoginHandler, Body))
|
||||
userGroup.POST("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.CreateUser, Body))
|
||||
userGroup.PUT("/password", middle.RolePermission(constants.ROLE_USER), bind(api.UserApi.ChangePassword, Body))
|
||||
userGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.DeleteUser, Query))
|
||||
userGroup.GET("", middle.RolePermission(constants.ROLE_ROOT), bind(api.UserApi.GetUserList, None))
|
||||
userGroup.POST("", middle.RolePermission(eum.RoleRoot), bind(api.UserApi.CreateUser, Body))
|
||||
userGroup.PUT("/password", middle.RolePermission(eum.RoleUser), bind(api.UserApi.ChangePassword, Body))
|
||||
userGroup.DELETE("", middle.RolePermission(eum.RoleRoot), bind(api.UserApi.DeleteUser, Query))
|
||||
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("", bind(api.PushApi.GetPushById, Query))
|
||||
@@ -115,26 +115,26 @@ func routePathInit(r *gin.Engine) {
|
||||
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.PUT("", bind(api.FileApi.FileWriteHandler, None))
|
||||
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.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.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.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None))
|
||||
|
@@ -4,7 +4,6 @@
|
||||
package bleve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/v2"
|
||||
@@ -74,7 +73,6 @@ func (b *bleveSearch) Insert(logContent string, processName string, using string
|
||||
}); err != nil {
|
||||
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) {
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"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/log"
|
||||
"github.com/lzh-1625/go_process_manager/utils"
|
||||
@@ -49,7 +49,7 @@ func (t *tui) drawProcessList() {
|
||||
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() {
|
||||
if v.State.State != 1 || v.TermType != constants.TERMINAL_PTY {
|
||||
if v.State.State != 1 || v.TermType != eum.TerminalPty {
|
||||
return
|
||||
}
|
||||
t.teminal(v.Uuid)
|
||||
@@ -75,8 +75,8 @@ func (t *tui) teminal(uuid int) {
|
||||
tci := &TermConnectInstance{
|
||||
CancelFunc: cancel,
|
||||
}
|
||||
p.AddConn(constants.CONSOLE, tci)
|
||||
defer p.DeleteConn(constants.CONSOLE)
|
||||
p.AddConn(eum.Console, tci)
|
||||
defer p.DeleteConn(eum.Console)
|
||||
os.Stdin.Write([]byte("\033[H\033[2J")) // 清空屏幕
|
||||
p.ReadCache(tci)
|
||||
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) {
|
||||
switch p.Type() {
|
||||
case constants.TERMINAL_PTY:
|
||||
case eum.TerminalPty:
|
||||
{
|
||||
t.ptyConnect(p, ctx, cancel)
|
||||
}
|
||||
case constants.TERMINAL_STD:
|
||||
case eum.TerminalStd:
|
||||
{
|
||||
t.stdConnect(p, ctx, cancel)
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
_ "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/model"
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestCgroup(t *testing.T) {
|
||||
Name: "test",
|
||||
Cmd: "bash",
|
||||
Cwd: `/root`,
|
||||
TermType: constants.TERMINAL_PTY,
|
||||
TermType: eum.TerminalPty,
|
||||
})
|
||||
if err != nil {
|
||||
t.FailNow()
|
||||
|
6
resources/package-lock.json
generated
6
resources/package-lock.json
generated
@@ -1636,9 +1636,9 @@
|
||||
"url": "https://opencollective.com/popperjs"
|
||||
}
|
||||
},
|
||||
"node_modules/@remirror/core-constants": {
|
||||
"node_modules/@remirror/core-eum": {
|
||||
"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==",
|
||||
"license": "MIT"
|
||||
},
|
||||
@@ -5474,7 +5474,7 @@
|
||||
"integrity": "sha512-xiun5/3q0w5eRnGYfNlW1uU9W6x5MoFKWwq/0TIRgt09lv7Hcser2QYV8t4muXbEr+Fwo0geYn79Xs4GKywrRQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@remirror/core-constants": "3.0.0",
|
||||
"@remirror/core-eum": "3.0.0",
|
||||
"escape-string-regexp": "^4.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
Reference in New Issue
Block a user