mirror of
				https://github.com/lzh-1625/go_process_manager.git
				synced 2025-10-31 11:26:49 +08:00 
			
		
		
		
	Compare commits
	
		
			74 Commits
		
	
	
		
			master
			...
			f723c12d42
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | f723c12d42 | ||
|   | da54e71c27 | ||
|   | 0d46bb7d07 | ||
|   | cffb1ee0f4 | ||
|   | 143cf61a57 | ||
|   | 1dc2d77e82 | ||
|   | 37748ecb7f | ||
|   | 5de8b45b2f | ||
|   | 3fb8cd4dad | ||
|   | 274a4d93df | ||
|   | c383e1737f | ||
|   | 2a40d560d4 | ||
|   | d968ce2a3e | ||
|   | 51ff529a88 | ||
|   | ed237e1ddb | ||
|   | f980e79e02 | ||
|   | cb15544ea3 | ||
|   | c69056d1b7 | ||
|   | 39b199eac6 | ||
|   | 4343dfaa31 | ||
|   | 0e09afe962 | ||
|   | 5356eb4199 | ||
|   | b4c7ab9f2c | ||
|   | b307808b70 | ||
|   | 6aac70de9a | ||
|   | b598b590e7 | ||
|   | c3262afe13 | ||
|   | 9823ca0cef | ||
|   | b4ad29e9cf | ||
|   | dca76fd5d3 | ||
|   | ba36662759 | ||
|   | 3f5deab95a | ||
|   | a9657d35b8 | ||
|   | 0b4133e510 | ||
|   | c54e81321e | ||
|   | a1ab697848 | ||
|   | c154abe568 | ||
|   | 39dc4f13e4 | ||
|   | 8aa700407c | ||
|   | 726c5f861d | ||
|   | 0db3e60460 | ||
|   | ec9f1fefdb | ||
|   | a05d9c3f03 | ||
|   | cf184745ed | ||
|   | be73582e28 | ||
|   | 0fae7cac25 | ||
|   | efcf8d9ca6 | ||
|   | f1b27e85f4 | ||
|   | 63ffe4c8b5 | ||
|   | d5bc463b59 | ||
|   | 52616e29d9 | ||
|   | d809df5cda | ||
|   | 167afe2926 | ||
|   | 3ca28b0f44 | ||
|   | 8a175d33aa | ||
|   | af941de7f2 | ||
|   | 88bba5d4b5 | ||
|   | 62e51f4341 | ||
|   | acc623e5ec | ||
|   | fd79a72115 | ||
|   | 1b6c55a88d | ||
|   | 4541d951f5 | ||
|   | dfd813bfdd | ||
|   | bc9e33ab4d | ||
|   | b39302822f | ||
|   | 19bbd14265 | ||
|   | d1d336fe03 | ||
|   | 54de27d1d6 | ||
|   | 172e668fc5 | ||
|   | 3060ef5bbb | ||
|   | 3f8ef92b19 | ||
|   | d533d345ec | ||
|   | be6bbef98c | ||
|   | eb43a549e2 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -6,3 +6,4 @@ config.yaml | ||||
| ltest | ||||
| gtest | ||||
| mtest | ||||
| log.bleve | ||||
							
								
								
									
										22
									
								
								boot/boot.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								boot/boot.go
									
									
									
									
									
								
							| @@ -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" | ||||
| @@ -25,9 +25,8 @@ func init() { | ||||
| 	initArgs() | ||||
| 	initLogHandle() | ||||
| 	initLog() | ||||
| 	initEs() | ||||
| 	initLogHanler() | ||||
| 	initCondTiming() | ||||
| 	initWaitCond() | ||||
| 	initProcess() | ||||
| 	initJwtSecret() | ||||
| 	initTui() | ||||
| @@ -82,21 +81,17 @@ func initLog() { | ||||
| 	logger.InitLog() | ||||
| } | ||||
|  | ||||
| func initEs() { | ||||
| 	logic.EsLogic.InitEs() | ||||
| } | ||||
|  | ||||
| func initProcess() { | ||||
| 	logic.ProcessCtlLogic.ProcessInit() | ||||
| } | ||||
|  | ||||
| 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)) | ||||
| } | ||||
|  | ||||
| @@ -128,16 +123,17 @@ func initListenKillSignal() { | ||||
| 		sigs := make(chan os.Signal, 1) | ||||
| 		signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||||
| 		<-sigs | ||||
| 		logger.Logger.Info("进程正在退出,等待全部进程停止") | ||||
| 		logic.ProcessCtlLogic.KillAllProcess() | ||||
| 		log.Print("已停止所有进程") | ||||
| 		os.Exit(0) | ||||
| 	}() | ||||
| } | ||||
|  | ||||
| func initCondTiming() { | ||||
| 	middle.InitCondTiming() | ||||
| } | ||||
|  | ||||
| func initLogHandle() { | ||||
| 	logic.InitLogHandle() | ||||
| } | ||||
|  | ||||
| func initWaitCond() { | ||||
| 	middle.InitWaitCond() | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
|   SET CGO_ENABLED=0 | ||||
|   SET GOOS=linux | ||||
|   SET GOARCH=amd64 | ||||
|   go build -ldflags="-s -w" -o go_process_manager cmd/go_process_manager/main.go | ||||
| SET CGO_ENABLED=0 | ||||
| SET GOOS=linux | ||||
| SET GOARCH=amd64 | ||||
| @REM go build -ldflags="-s -w" -tags="slim" -o go_process_manager -trimpath cmd/go_process_manager/main.go | ||||
| go build -ldflags="-s -w" -o go_process_manager -trimpath cmd/go_process_manager/main.go | ||||
							
								
								
									
										5
									
								
								build.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								build.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| export CGO_ENABLED=0 | ||||
| export GOOS=linux | ||||
| export GOARCH=amd64 | ||||
| # go build -ldflags="-s -w" -tags="slim" -o go_process_manager -trimpath cmd/go_process_manager/main.go | ||||
| go build -ldflags="-s -w" -o go_process_manager -trimpath cmd/go_process_manager/main.go | ||||
| @@ -7,7 +7,34 @@ import ( | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
|  | ||||
| var startTitle = ` | ||||
| ---------------------------------------------------------------------------- | ||||
|           _____                    _____                    _____           | ||||
|          /\    \                  /\    \                  /\    \          | ||||
|         /::\    \                /::\    \                /::\____\         | ||||
|        /::::\    \              /::::\    \              /::::|   |         | ||||
|       /::::::\    \            /::::::\    \            /:::::|   |         | ||||
|      /:::/\:::\    \          /:::/\:::\    \          /::::::|   |         | ||||
|     /:::/  \:::\    \        /:::/__\:::\    \        /:::/|::|   |         | ||||
|    /:::/    \:::\    \      /::::\   \:::\    \      /:::/ |::|   |         | ||||
|   /:::/    / \:::\    \    /::::::\   \:::\    \    /:::/  |::|___|______   | ||||
|  /:::/    /   \:::\ ___\  /:::/\:::\   \:::\____\  /:::/   |::::::::\    \  | ||||
| /:::/____/  ___\:::|    |/:::/  \:::\   \:::|    |/:::/    |:::::::::\____\ | ||||
| \:::\    \ /\  /:::|____|\::/    \:::\  /:::|____|\::/    / ~~~~~/:::/    / | ||||
|  \:::\    /::\ \::/    /  \/_____/\:::\/:::/    /  \/____/      /:::/    /  | ||||
|   \:::\   \:::\ \/____/            \::::::/    /               /:::/    /   | ||||
|    \:::\   \:::\____\               \::::/    /               /:::/    /    | ||||
|     \:::\  /:::/    /                \::/____/               /:::/    /     | ||||
|      \:::\/:::/    /                  ~~                    /:::/    /      | ||||
|       \::::::/    /                                        /:::/    /       | ||||
|        \::::/    /                                        /:::/    /        | ||||
|         \::/____/                                         \::/    /         | ||||
|                                                            \/____/          | ||||
| ----------------------------------------------------------------------------   | ||||
| ` | ||||
|  | ||||
| func main() { | ||||
| 	print(startTitle) | ||||
| 	gin.SetMode(gin.ReleaseMode) | ||||
| 	route.Route() | ||||
| } | ||||
|   | ||||
| @@ -4,33 +4,34 @@ var CF = new(configuration) | ||||
|  | ||||
| // 只支持 float64、int、int64、bool、string类型 | ||||
| type configuration struct { | ||||
| 	LogLevel                  string  `default:"debug"  describe:"日志等级[debug,info]"` | ||||
| 	Listen                    string  `default:":8797" describe:"监听端口"` | ||||
| 	EsEnable                  bool    `default:"false" describe:"启用Elasticsearch"` | ||||
| 	EsUrl                     string  `default:"" describe:"Elasticsearch url"` | ||||
| 	EsIndex                   string  `default:"server_log_v1" describe:"Elasticsearch index"` | ||||
| 	EsUsername                string  `default:"" describe:"Elasticsearch用户名"` | ||||
| 	EsPassword                string  `default:"" describe:"Elasticsearch密码"` | ||||
| 	EsWindowLimit             bool    `default:"true" describe:"Es分页10000条限制"` | ||||
| 	FileSizeLimit             float64 `default:"10.0" describe:"文件大小限制(MB)"` | ||||
| 	ProcessInputPrefix        string  `default:">" describe:"进程输入前缀"` | ||||
| 	ProcessRestartsLimit      int     `default:"2" describe:"进程重启次数限制"` | ||||
| 	ProcessMsgCacheLinesLimit int     `default:"50" describe:"std进程缓存消息行数"` | ||||
| 	ProcessMsgCacheBufLimit   int     `default:"4096" describe:"pty进程缓存消息字节长度"` | ||||
| 	ProcessExpireTime         int64   `default:"60" describe:"进程控制权过期时间(秒)"` | ||||
| 	PerformanceInfoListLength int     `default:"30" describe:"性能信息存储长度"` | ||||
| 	PerformanceInfoInterval   int     `default:"60" describe:"监控获取间隔时间(秒)"` | ||||
| 	TerminalConnectTimeout    int     `default:"10" describe:"终端连接超时时间(分钟)"` | ||||
| 	UserPassWordMinLength     int     `default:"4" describe:"用户密码最小长度"` | ||||
| 	LogMinLenth               int     `default:"0" describe:"过滤日志最小长度"` | ||||
| 	LogHandlerPoolSize        int     `default:"10" describe:"日志处理并行数"` | ||||
| 	PprofEnable               bool    `default:"true" describe:"启用pprof分析工具"` | ||||
| 	KillWaitTime              int     `default:"5" describe:"kill信号等待时间(秒)"` | ||||
| 	TaskTimeout               int     `default:"60" describe:"任务执行超时时间(秒)"` | ||||
| 	TokenExpirationTime       int64   `default:"720" describe:"token过期时间(小时)"` | ||||
| 	WsHealthCheckInterval     int     `default:"3" describe:"ws主动健康检查间隔(秒)"` | ||||
| 	CgroupPeriod              int64   `default:"100000" describe:"CgroupPeriod"` | ||||
| 	CgroupSwapLimit           bool    `default:"false" describe:"cgroup swap限制"` | ||||
| 	CondWaitTime              int     `default:"30" describe:"长轮询等待时间(秒)"` | ||||
| 	Tui                       bool    `default:"-"` | ||||
| 	LogLevel                   string  `default:"debug"  describe:"日志等级[debug,info]"` | ||||
| 	Listen                     string  `default:":8797" describe:"监听端口"` | ||||
| 	StorgeType                 string  `default:"sqlite" describe:"存储引擎[sqlite、es、bleve]"` | ||||
| 	EsUrl                      string  `default:"" describe:"Elasticsearch url"` | ||||
| 	EsIndex                    string  `default:"server_log_v1" describe:"Elasticsearch index"` | ||||
| 	EsUsername                 string  `default:"" describe:"Elasticsearch用户名"` | ||||
| 	EsPassword                 string  `default:"" describe:"Elasticsearch密码"` | ||||
| 	EsWindowLimit              bool    `default:"true" describe:"Es分页10000条限制"` | ||||
| 	FileSizeLimit              float64 `default:"10.0" describe:"文件大小限制(MB)"` | ||||
| 	ProcessInputPrefix         string  `default:">" describe:"进程输入前缀"` | ||||
| 	ProcessRestartsLimit       int     `default:"2" describe:"进程重启次数限制"` | ||||
| 	ProcessMsgCacheLinesLimit  int     `default:"50" describe:"std进程缓存消息行数"` | ||||
| 	ProcessMsgCacheBufLimit    int     `default:"4096" describe:"pty进程缓存消息字节长度"` | ||||
| 	ProcessExpireTime          int64   `default:"60" describe:"进程控制权过期时间(秒)"` | ||||
| 	PerformanceInfoListLength  int     `default:"30" describe:"性能信息存储长度"` | ||||
| 	PerformanceInfoInterval    int     `default:"60" describe:"监控获取间隔时间(秒)"` | ||||
| 	TerminalConnectTimeout     int     `default:"10" describe:"终端连接超时时间(分钟)"` | ||||
| 	UserPassWordMinLength      int     `default:"4" describe:"用户密码最小长度"` | ||||
| 	LogMinLenth                int     `default:"0" describe:"过滤日志最小长度"` | ||||
| 	LogHandlerPoolSize         int     `default:"10" describe:"日志处理并行数"` | ||||
| 	PprofEnable                bool    `default:"true" describe:"启用pprof分析工具"` | ||||
| 	KillWaitTime               int     `default:"5" describe:"kill信号等待时间(秒)"` | ||||
| 	TaskTimeout                int     `default:"60" describe:"任务执行超时时间(秒)"` | ||||
| 	TokenExpirationTime        int64   `default:"720" describe:"token过期时间(小时)"` | ||||
| 	WsHealthCheckInterval      int     `default:"3" describe:"ws主动健康检查间隔(秒)"` | ||||
| 	CgroupPeriod               int64   `default:"100000" describe:"CgroupPeriod"` | ||||
| 	CgroupSwapLimit            bool    `default:"false" describe:"cgroup swap限制"` | ||||
| 	CondWaitTime               int     `default:"30" describe:"长轮询等待时间(秒)"` | ||||
| 	PerformanceCapacityDisplay bool    `default:"false" describe:"性能资源容量显示"` | ||||
| 	Tui                        bool    `default:"-"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										59
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										59
									
								
								go.mod
									
									
									
									
									
								
							| @@ -6,14 +6,45 @@ require ( | ||||
| 	github.com/containerd/cgroups/v3 v3.0.4 | ||||
| 	github.com/gorilla/websocket v1.5.1 | ||||
| 	github.com/opencontainers/runtime-spec v1.2.0 | ||||
| 	github.com/vcaesar/gse-bleve v0.40.0 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect | ||||
| 	github.com/bits-and-blooms/bitset v1.22.0 // indirect | ||||
| 	github.com/blevesearch/bleve_index_api v1.2.8 // indirect | ||||
| 	github.com/blevesearch/geo v0.2.3 // indirect | ||||
| 	github.com/blevesearch/go-faiss v1.0.25 // indirect | ||||
| 	github.com/blevesearch/go-porterstemmer v1.0.3 // indirect | ||||
| 	github.com/blevesearch/gtreap v0.1.1 // indirect | ||||
| 	github.com/blevesearch/mmap-go v1.0.4 // indirect | ||||
| 	github.com/blevesearch/scorch_segment_api/v2 v2.3.10 // indirect | ||||
| 	github.com/blevesearch/segment v0.9.1 // indirect | ||||
| 	github.com/blevesearch/snowballstem v0.9.0 // indirect | ||||
| 	github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect | ||||
| 	github.com/blevesearch/vellum v1.1.0 // indirect | ||||
| 	github.com/blevesearch/zapx/v11 v11.4.2 // indirect | ||||
| 	github.com/blevesearch/zapx/v12 v12.4.2 // indirect | ||||
| 	github.com/blevesearch/zapx/v13 v13.4.2 // indirect | ||||
| 	github.com/blevesearch/zapx/v14 v14.4.2 // indirect | ||||
| 	github.com/blevesearch/zapx/v15 v15.4.2 // indirect | ||||
| 	github.com/blevesearch/zapx/v16 v16.2.4 // indirect | ||||
| 	github.com/go-ego/gse v0.70.2 // indirect | ||||
| 	github.com/golang/protobuf v1.5.2 // indirect | ||||
| 	github.com/golang/snappy v0.0.4 // indirect | ||||
| 	github.com/mschoch/smat v0.2.0 // indirect | ||||
| 	github.com/vcaesar/cedar v0.20.1 // indirect | ||||
| 	go.etcd.io/bbolt v1.4.0 // indirect | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	filippo.io/edwards25519 v1.1.0 // indirect | ||||
| 	github.com/cilium/ebpf v0.16.0 // indirect | ||||
| 	github.com/containerd/log v0.1.0 // indirect | ||||
| 	github.com/coreos/go-systemd/v22 v22.5.0 // indirect | ||||
| 	github.com/docker/go-units v0.5.0 // indirect | ||||
| 	github.com/go-ole/go-ole v1.2.6 // indirect | ||||
| 	github.com/go-sql-driver/mysql v1.8.1 // indirect | ||||
| 	github.com/godbus/dbus/v5 v5.1.0 // indirect | ||||
| 	github.com/iamacarpet/go-winpty v1.0.2 // indirect | ||||
| 	github.com/josharian/intern v1.0.0 // indirect | ||||
| @@ -25,13 +56,19 @@ require ( | ||||
| 	github.com/tklauser/numcpus v0.7.0 // indirect | ||||
| 	github.com/yusufpapurcu/wmi v1.2.4 // indirect | ||||
| 	golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect | ||||
| 	golang.org/x/sync v0.9.0 // indirect | ||||
| 	golang.org/x/mod v0.22.0 // indirect | ||||
| 	golang.org/x/sync v0.11.0 // indirect | ||||
| 	golang.org/x/tools v0.27.0 // indirect | ||||
| 	gorm.io/datatypes v1.2.4 // indirect | ||||
| 	gorm.io/driver/mysql v1.5.6 // indirect | ||||
| 	gorm.io/hints v1.1.0 // indirect | ||||
| 	gorm.io/plugin/dbresolver v1.5.0 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	github.com/jinzhu/inflection v1.0.0 // indirect | ||||
| 	github.com/jinzhu/now v1.1.5 // indirect | ||||
| 	gorm.io/gorm v1.25.7 | ||||
| 	gorm.io/gorm v1.25.11 | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| @@ -40,13 +77,13 @@ require ( | ||||
| 	github.com/gdamore/encoding v1.0.0 // indirect | ||||
| 	github.com/gdamore/tcell/v2 v2.7.1 // indirect | ||||
| 	github.com/glebarez/go-sqlite v1.21.2 // indirect | ||||
| 	github.com/google/uuid v1.3.0 // indirect | ||||
| 	github.com/google/uuid v1.6.0 | ||||
| 	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect | ||||
| 	github.com/mattn/go-runewidth v0.0.15 // indirect | ||||
| 	github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect | ||||
| 	github.com/rivo/tview v0.0.0-20241016194538-c5e4fb24af13 | ||||
| 	github.com/rivo/uniseg v0.4.7 // indirect | ||||
| 	golang.org/x/term v0.19.0 // indirect | ||||
| 	golang.org/x/term v0.26.0 // indirect | ||||
| 	gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||||
| 	modernc.org/libc v1.22.5 // indirect | ||||
| 	modernc.org/mathutil v1.5.0 // indirect | ||||
| @@ -77,24 +114,26 @@ require ( | ||||
| 	github.com/ugorji/go/codec v1.2.12 // indirect | ||||
| 	go.uber.org/multierr v1.10.0 // indirect | ||||
| 	golang.org/x/arch v0.8.0 // indirect | ||||
| 	golang.org/x/crypto v0.22.0 // indirect | ||||
| 	golang.org/x/sys v0.27.0 // indirect | ||||
| 	golang.org/x/text v0.15.0 // indirect | ||||
| 	golang.org/x/crypto v0.29.0 // indirect | ||||
| 	golang.org/x/sys v0.29.0 // indirect | ||||
| 	golang.org/x/text v0.22.0 // indirect | ||||
| 	google.golang.org/protobuf v1.35.2 // indirect | ||||
| 	gopkg.in/yaml.v3 v3.0.1 // indirect | ||||
| ) | ||||
|  | ||||
| require ( | ||||
| 	github.com/blevesearch/bleve/v2 v2.5.2 | ||||
| 	github.com/creack/pty v1.1.21 | ||||
| 	github.com/gin-gonic/gin v1.9.1 | ||||
| 	github.com/glebarez/sqlite v1.11.0 | ||||
| 	github.com/golang-jwt/jwt v3.2.2+incompatible | ||||
| 	github.com/golang-jwt/jwt/v5 v5.2.3 | ||||
| 	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 | ||||
| 	github.com/olivere/elastic/v7 v7.0.32 | ||||
| 	github.com/panjf2000/ants/v2 v2.10.0 | ||||
| 	github.com/robfig/cron/v3 v3.0.1 | ||||
| 	github.com/runletapp/go-console v0.0.0-20211204140000-27323a28410a | ||||
| 	github.com/shirou/gopsutil v3.21.11+incompatible | ||||
| 	github.com/timandy/routine v1.1.4 | ||||
| 	go.uber.org/zap v1.26.0 | ||||
| 	golang.org/x/net v0.24.0 // indirect | ||||
| 	golang.org/x/net v0.31.0 // indirect | ||||
| 	gorm.io/gen v0.3.27 | ||||
| ) | ||||
|   | ||||
							
								
								
									
										160
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										160
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,3 +1,46 @@ | ||||
| filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= | ||||
| filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= | ||||
| github.com/RoaringBitmap/roaring/v2 v2.4.5 h1:uGrrMreGjvAtTBobc0g5IrW1D5ldxDQYe2JW2gggRdg= | ||||
| github.com/RoaringBitmap/roaring/v2 v2.4.5/go.mod h1:FiJcsfkGje/nZBZgCu0ZxCPOKD/hVXDS2dXi7/eUFE0= | ||||
| github.com/bits-and-blooms/bitset v1.12.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= | ||||
| github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4= | ||||
| github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= | ||||
| github.com/blevesearch/bleve/v2 v2.5.2 h1:Ab0r0MODV2C5A6BEL87GqLBySqp/s9xFgceCju6BQk8= | ||||
| github.com/blevesearch/bleve/v2 v2.5.2/go.mod h1:5Dj6dUQxZM6aqYT3eutTD/GpWKGFSsV8f7LDidFbwXo= | ||||
| github.com/blevesearch/bleve_index_api v1.2.8 h1:Y98Pu5/MdlkRyLM0qDHostYo7i+Vv1cDNhqTeR4Sy6Y= | ||||
| github.com/blevesearch/bleve_index_api v1.2.8/go.mod h1:rKQDl4u51uwafZxFrPD1R7xFOwKnzZW7s/LSeK4lgo0= | ||||
| github.com/blevesearch/geo v0.2.3 h1:K9/vbGI9ehlXdxjxDRJtoAMt7zGAsMIzc6n8zWcwnhg= | ||||
| github.com/blevesearch/geo v0.2.3/go.mod h1:K56Q33AzXt2YExVHGObtmRSFYZKYGv0JEN5mdacJJR8= | ||||
| github.com/blevesearch/go-faiss v1.0.25 h1:lel1rkOUGbT1CJ0YgzKwC7k+XH0XVBHnCVWahdCXk4U= | ||||
| github.com/blevesearch/go-faiss v1.0.25/go.mod h1:OMGQwOaRRYxrmeNdMrXJPvVx8gBnvE5RYrr0BahNnkk= | ||||
| github.com/blevesearch/go-porterstemmer v1.0.3 h1:GtmsqID0aZdCSNiY8SkuPJ12pD4jI+DdXTAn4YRcHCo= | ||||
| github.com/blevesearch/go-porterstemmer v1.0.3/go.mod h1:angGc5Ht+k2xhJdZi511LtmxuEf0OVpvUUNrwmM1P7M= | ||||
| github.com/blevesearch/gtreap v0.1.1 h1:2JWigFrzDMR+42WGIN/V2p0cUvn4UP3C4Q5nmaZGW8Y= | ||||
| github.com/blevesearch/gtreap v0.1.1/go.mod h1:QaQyDRAT51sotthUWAH4Sj08awFSSWzgYICSZ3w0tYk= | ||||
| github.com/blevesearch/mmap-go v1.0.4 h1:OVhDhT5B/M1HNPpYPBKIEJaD0F3Si+CrEKULGCDPWmc= | ||||
| github.com/blevesearch/mmap-go v1.0.4/go.mod h1:EWmEAOmdAS9z/pi/+Toxu99DnsbhG1TIxUoRmJw/pSs= | ||||
| github.com/blevesearch/scorch_segment_api/v2 v2.3.10 h1:Yqk0XD1mE0fDZAJXTjawJ8If/85JxnLd8v5vG/jWE/s= | ||||
| github.com/blevesearch/scorch_segment_api/v2 v2.3.10/go.mod h1:Z3e6ChN3qyN35yaQpl00MfI5s8AxUJbpTR/DL8QOQ+8= | ||||
| github.com/blevesearch/segment v0.9.1 h1:+dThDy+Lvgj5JMxhmOVlgFfkUtZV2kw49xax4+jTfSU= | ||||
| github.com/blevesearch/segment v0.9.1/go.mod h1:zN21iLm7+GnBHWTao9I+Au/7MBiL8pPFtJBJTsk6kQw= | ||||
| github.com/blevesearch/snowballstem v0.9.0 h1:lMQ189YspGP6sXvZQ4WZ+MLawfV8wOmPoD/iWeNXm8s= | ||||
| github.com/blevesearch/snowballstem v0.9.0/go.mod h1:PivSj3JMc8WuaFkTSRDW2SlrulNWPl4ABg1tC/hlgLs= | ||||
| github.com/blevesearch/upsidedown_store_api v1.0.2 h1:U53Q6YoWEARVLd1OYNc9kvhBMGZzVrdmaozG2MfoB+A= | ||||
| github.com/blevesearch/upsidedown_store_api v1.0.2/go.mod h1:M01mh3Gpfy56Ps/UXHjEO/knbqyQ1Oamg8If49gRwrQ= | ||||
| github.com/blevesearch/vellum v1.1.0 h1:CinkGyIsgVlYf8Y2LUQHvdelgXr6PYuvoDIajq6yR9w= | ||||
| github.com/blevesearch/vellum v1.1.0/go.mod h1:QgwWryE8ThtNPxtgWJof5ndPfx0/YMBh+W2weHKPw8Y= | ||||
| github.com/blevesearch/zapx/v11 v11.4.2 h1:l46SV+b0gFN+Rw3wUI1YdMWdSAVhskYuvxlcgpQFljs= | ||||
| github.com/blevesearch/zapx/v11 v11.4.2/go.mod h1:4gdeyy9oGa/lLa6D34R9daXNUvfMPZqUYjPwiLmekwc= | ||||
| github.com/blevesearch/zapx/v12 v12.4.2 h1:fzRbhllQmEMUuAQ7zBuMvKRlcPA5ESTgWlDEoB9uQNE= | ||||
| github.com/blevesearch/zapx/v12 v12.4.2/go.mod h1:TdFmr7afSz1hFh/SIBCCZvcLfzYvievIH6aEISCte58= | ||||
| github.com/blevesearch/zapx/v13 v13.4.2 h1:46PIZCO/ZuKZYgxI8Y7lOJqX3Irkc3N8W82QTK3MVks= | ||||
| github.com/blevesearch/zapx/v13 v13.4.2/go.mod h1:knK8z2NdQHlb5ot/uj8wuvOq5PhDGjNYQQy0QDnopZk= | ||||
| github.com/blevesearch/zapx/v14 v14.4.2 h1:2SGHakVKd+TrtEqpfeq8X+So5PShQ5nW6GNxT7fWYz0= | ||||
| github.com/blevesearch/zapx/v14 v14.4.2/go.mod h1:rz0XNb/OZSMjNorufDGSpFpjoFKhXmppH9Hi7a877D8= | ||||
| github.com/blevesearch/zapx/v15 v15.4.2 h1:sWxpDE0QQOTjyxYbAVjt3+0ieu8NCE0fDRaFxEsp31k= | ||||
| github.com/blevesearch/zapx/v15 v15.4.2/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw= | ||||
| github.com/blevesearch/zapx/v16 v16.2.4 h1:tGgfvleXTAkwsD5mEzgM3zCS/7pgocTCnO1oyAUjlww= | ||||
| github.com/blevesearch/zapx/v16 v16.2.4/go.mod h1:Rti/REtuuMmzwsI8/C/qIzRaEoSK/wiFYw5e5ctUKKs= | ||||
| github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= | ||||
| github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= | ||||
| github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= | ||||
| @@ -43,6 +86,8 @@ github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9g | ||||
| github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= | ||||
| github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= | ||||
| github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= | ||||
| github.com/go-ego/gse v0.70.2 h1:y2UMOHJMtI+0b2GjxTtQfKON5DMmlyX1hOQHTo8UVVs= | ||||
| github.com/go-ego/gse v0.70.2/go.mod h1:kesekpZfcFQ/kwd9b27VZHUOH5dQUjaaQUZ4OGt4Hj4= | ||||
| github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= | ||||
| github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= | ||||
| github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= | ||||
| @@ -55,26 +100,52 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx | ||||
| github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= | ||||
| github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= | ||||
| github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= | ||||
| github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | ||||
| github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= | ||||
| github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= | ||||
| github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= | ||||
| github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= | ||||
| github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= | ||||
| github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= | ||||
| github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= | ||||
| github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= | ||||
| github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY= | ||||
| github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= | ||||
| github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||||
| github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||
| github.com/golang-jwt/jwt/v5 v5.2.3 h1:kkGXqQOBSDDWRhWNXTFpqGSCMyh/PLnqUvMGJPDJDs0= | ||||
| github.com/golang-jwt/jwt/v5 v5.2.3/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= | ||||
| github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= | ||||
| github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= | ||||
| github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= | ||||
| github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= | ||||
| github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= | ||||
| github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= | ||||
| github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= | ||||
| github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= | ||||
| github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | ||||
| github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||||
| github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= | ||||
| github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= | ||||
| github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | ||||
| github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= | ||||
| github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= | ||||
| github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= | ||||
| github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= | ||||
| github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= | ||||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||
| github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= | ||||
| github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= | ||||
| github.com/iamacarpet/go-winpty v1.0.2 h1:jwPVTYrjAHZx6Mcm6K5i9G4opMp5TblEHH5EQCl/Gzw= | ||||
| github.com/iamacarpet/go-winpty v1.0.2/go.mod h1:/GHKJicG/EVRQIK1IQikMYBakBkhj/3hTjLgdzYsmpI= | ||||
| github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= | ||||
| github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= | ||||
| github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= | ||||
| github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= | ||||
| github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= | ||||
| github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= | ||||
| github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= | ||||
| github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= | ||||
| github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= | ||||
| github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= | ||||
| github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||
| github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||
| github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= | ||||
| github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= | ||||
| github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= | ||||
| @@ -103,10 +174,15 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE | ||||
| github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= | ||||
| github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= | ||||
| github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||||
| github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= | ||||
| github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= | ||||
| github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= | ||||
| github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g= | ||||
| github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= | ||||
| github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= | ||||
| github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= | ||||
| github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE= | ||||
| github.com/microsoft/go-mssqldb v0.17.0/go.mod h1:OkoNGhGEs8EZqchVTtochlXruEhEOaO4S0d2sB5aeGQ= | ||||
| github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= | ||||
| github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= | ||||
| github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||
| @@ -114,6 +190,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w | ||||
| github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||||
| github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= | ||||
| github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= | ||||
| github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM= | ||||
| github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw= | ||||
| github.com/olivere/elastic/v7 v7.0.32 h1:R7CXvbu8Eq+WlsLgxmKVKPox0oOwAE/2T9Si5BnvK6E= | ||||
| github.com/olivere/elastic/v7 v7.0.32/go.mod h1:c7PVmLe3Fxq77PIfY/bZmxY/TAamBhCzZ8xDOE09a9k= | ||||
| github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= | ||||
| @@ -156,10 +234,9 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO | ||||
| github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||||
| github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||||
| github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||||
| github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= | ||||
| github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||
| github.com/timandy/routine v1.1.4 h1:L9eAli/ROJcW6LhmwZcusYQcdAqxAXGOQhEXLQSNWOA= | ||||
| github.com/timandy/routine v1.1.4/go.mod h1:siBcl8iIsGmhLCajRGRcy7Y7FVcicNXkr97JODdt9fc= | ||||
| github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||||
| github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||
| github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4= | ||||
| github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0= | ||||
| github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4= | ||||
| @@ -168,9 +245,17 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS | ||||
| github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= | ||||
| github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= | ||||
| github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= | ||||
| github.com/vcaesar/cedar v0.20.1 h1:cDOmYWdprO7ZW8cngJrDi8Zivnscj9dA/y8Y+2SB1P0= | ||||
| github.com/vcaesar/cedar v0.20.1/go.mod h1:iMDweyuW76RvSrCkQeZeQk4iCbshiPzcCvcGCtpM7iI= | ||||
| github.com/vcaesar/gse-bleve v0.40.0 h1:Qnv/9v8uyqNkFHxdK4VLN4EwZ0WLxudSgBcUzd2uxQs= | ||||
| github.com/vcaesar/gse-bleve v0.40.0/go.mod h1:ORZ+jIAEIQeC6PEai24UJr8wisHAWrSukKXTPVVPXzc= | ||||
| github.com/vcaesar/tt v0.20.0 h1:9t2Ycb9RNHcP0WgQgIaRKJBB+FrRdejuaL6uWIHuoBA= | ||||
| github.com/vcaesar/tt v0.20.0/go.mod h1:GHPxQYhn+7OgKakRusH7KJ0M5MhywoeLb8Fcffs/Gtg= | ||||
| github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||||
| github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= | ||||
| github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= | ||||
| go.etcd.io/bbolt v1.4.0 h1:TU77id3TnN/zKr7CO/uk+fBCwF2jGcMuw2B/FMAzYIk= | ||||
| go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk= | ||||
| go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= | ||||
| go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= | ||||
| go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= | ||||
| @@ -182,24 +267,26 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= | ||||
| golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= | ||||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||||
| golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||||
| golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= | ||||
| golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= | ||||
| golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= | ||||
| golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= | ||||
| golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo= | ||||
| golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak= | ||||
| golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||||
| golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||||
| golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= | ||||
| golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= | ||||
| golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||||
| golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||||
| golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||||
| golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= | ||||
| golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= | ||||
| golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= | ||||
| golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= | ||||
| golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= | ||||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||||
| golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= | ||||
| golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= | ||||
| golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||||
| golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= | ||||
| golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= | ||||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||||
| golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| @@ -210,36 +297,65 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc | ||||
| golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= | ||||
| golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= | ||||
| golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||||
| golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||||
| golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||||
| golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= | ||||
| golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= | ||||
| golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= | ||||
| golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= | ||||
| golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= | ||||
| golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||||
| golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||||
| golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||||
| golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||||
| golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= | ||||
| golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||||
| golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= | ||||
| golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= | ||||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||||
| golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||||
| golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||||
| golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= | ||||
| golang.org/x/tools v0.27.0 h1:qEKojBykQkQ4EynWy4S8Weg69NumxKdn40Fce3uc/8o= | ||||
| golang.org/x/tools v0.27.0/go.mod h1:sUi0ZgbwW9ZPAq26Ekut+weQPR5eIM6GQLQ1Yjm1H0Q= | ||||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||||
| google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= | ||||
| google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= | ||||
| google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= | ||||
| google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= | ||||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= | ||||
| gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
| gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||
| gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A= | ||||
| gorm.io/datatypes v1.2.4 h1:uZmGAcK/QZ0uyfCuVg0VQY1ZmV9h1fuG0tMwKByO1z4= | ||||
| gorm.io/datatypes v1.2.4/go.mod h1:f4BsLcFAX67szSv8svwLRjklArSHAvHLeE3pXAS5DZI= | ||||
| gorm.io/driver/mysql v1.4.3/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= | ||||
| gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8= | ||||
| gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= | ||||
| gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U= | ||||
| gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= | ||||
| gorm.io/driver/sqlite v1.1.6/go.mod h1:W8LmC/6UvVbHKah0+QOC7Ja66EaZXHwUTjgXY8YNWX8= | ||||
| gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU= | ||||
| gorm.io/driver/sqlite v1.4.3/go.mod h1:0Aq3iPO+v9ZKbcdiz8gLWRw5VOPcBOPUQJFLq5e2ecI= | ||||
| gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0= | ||||
| gorm.io/driver/sqlserver v1.4.1/go.mod h1:DJ4P+MeZbc5rvY58PnmN1Lnyvb5gw5NPzGshHDnJLig= | ||||
| gorm.io/gen v0.3.27 h1:ziocAFLpE7e0g4Rum69pGfB9S6DweTxK8gAun7cU8as= | ||||
| gorm.io/gen v0.3.27/go.mod h1:9zquz2xD1f3Eb/eHq4oLn2z6vDVvQlCY5S3uMBLv4EA= | ||||
| gorm.io/gorm v1.21.15/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= | ||||
| gorm.io/gorm v1.22.2/go.mod h1:F+OptMscr0P2F2qU97WT1WimdH9GaQPoDW7AYd5i2Y0= | ||||
| gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= | ||||
| gorm.io/gorm v1.25.2/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= | ||||
| gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= | ||||
| gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg= | ||||
| gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ= | ||||
| gorm.io/hints v1.1.0 h1:Lp4z3rxREufSdxn4qmkK3TLDltrM10FLTHiuqwDPvXw= | ||||
| gorm.io/hints v1.1.0/go.mod h1:lKQ0JjySsPBj3uslFzY3JhYDtqEwzm+G1hv8rWujB6Y= | ||||
| gorm.io/plugin/dbresolver v1.5.0 h1:XVHLxh775eP0CqVh3vcfJtYqja3uFl5Wr3cKlY8jgDY= | ||||
| gorm.io/plugin/dbresolver v1.5.0/go.mod h1:l4Cn87EHLEYuqUncpEeTC2tTJQkjngPSD+lo8hIvcT0= | ||||
| modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= | ||||
| modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= | ||||
| modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= | ||||
|   | ||||
| @@ -1,75 +1,64 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
| 	"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/lzh-1625/go_process_manager/log" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
|  | ||||
| func rOk(ctx *gin.Context, message string, data any) { | ||||
| 	jsonData := map[string]any{ | ||||
| 		"code": 0, | ||||
| 		"msg":  message, | ||||
| func getRole(ctx *gin.Context) eum.Role { | ||||
| 	if v, ok := ctx.Get(eum.CtxRole); ok { | ||||
| 		return v.(eum.Role) | ||||
| 	} | ||||
| 	if data != nil { | ||||
| 		jsonData["data"] = data | ||||
| 	} | ||||
| 	ctx.JSON(http.StatusOK, jsonData) | ||||
| } | ||||
|  | ||||
| func errCheck(ctx *gin.Context, isErr bool, errData any) { | ||||
| 	if !isErr { | ||||
| 		return | ||||
| 	} | ||||
| 	if err, ok := errData.(error); ok { | ||||
| 		log.Logger.Warn(errData) | ||||
| 		ctx.Set(constants.CTXFLG_ERR, err.Error()) | ||||
| 	} | ||||
| 	if err, ok := errData.(string); ok { | ||||
| 		ctx.Set(constants.CTXFLG_ERR, err) | ||||
| 	} | ||||
| 	panic(0) | ||||
| } | ||||
|  | ||||
| func getRole(ctx *gin.Context) constants.Role { | ||||
| 	if v, ok := ctx.Get(constants.CTXFLG_ROLE); ok { | ||||
| 		return v.(constants.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() | ||||
| } | ||||
|  | ||||
| func getQueryInt(ctx *gin.Context, query string) (i int) { | ||||
| 	i, err := strconv.Atoi(ctx.Query(query)) | ||||
| 	errCheck(ctx, err != nil, "Invalid parameters!") | ||||
| 	return | ||||
| type Response struct { | ||||
| 	StatusCode int | ||||
| 	Code       int | ||||
| 	Data       any | ||||
| 	Msg        string | ||||
| } | ||||
|  | ||||
| func getQueryString(ctx *gin.Context, query string) (s string) { | ||||
| 	s = ctx.Query(query) | ||||
| 	errCheck(ctx, s == "", "Invalid parameters!") | ||||
| 	return | ||||
| func NewResponse() *Response { | ||||
| 	return &Response{StatusCode: 200} | ||||
| } | ||||
|  | ||||
| func bind[T any](ctx *gin.Context) T { | ||||
| 	var data T | ||||
| 	errCheck(ctx, ctx.ShouldBind(&data) != nil, "Invalid parameters!") | ||||
| 	return data | ||||
| func (r *Response) SetStatusCode(code int) *Response { | ||||
| 	r.StatusCode = code | ||||
| 	return r | ||||
| } | ||||
|  | ||||
| func (r *Response) SetDate(data any) *Response { | ||||
| 	r.Data = data | ||||
| 	return r | ||||
| } | ||||
|  | ||||
| func (r *Response) SetCode(code int) *Response { | ||||
| 	r.Code = code | ||||
| 	return r | ||||
| } | ||||
|  | ||||
| func (r *Response) SetMessage(msg any) *Response { | ||||
| 	if str, ok := msg.(string); ok { | ||||
| 		r.Msg = str | ||||
| 	} else if err, ok := msg.(error); ok { | ||||
| 		r.Msg = err.Error() | ||||
| 	} | ||||
| 	return r | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package api | ||||
|  | ||||
| import ( | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/logic" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
| @@ -10,18 +11,19 @@ type configApi struct{} | ||||
|  | ||||
| var ConfigApi = new(configApi) | ||||
|  | ||||
| func (c *configApi) GetSystemConfiguration(ctx *gin.Context) { | ||||
| 	result := logic.ConfigLogic.GetSystemConfiguration() | ||||
| 	rOk(ctx, "Operation successful!", result) | ||||
| func (c *configApi) GetSystemConfiguration(ctx *gin.Context, _ any) []model.SystemConfigurationVo { | ||||
| 	return logic.ConfigLogic.GetSystemConfiguration() | ||||
| } | ||||
|  | ||||
| func (c *configApi) SetSystemConfiguration(ctx *gin.Context) { | ||||
| 	req := bind[map[string]string](ctx) | ||||
| 	errCheck(ctx, logic.ConfigLogic.SetSystemConfiguration(req) != nil, "Set config fail!") | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (c *configApi) SetSystemConfiguration(ctx *gin.Context, _ any) (err error) { | ||||
| 	req := map[string]string{} | ||||
| 	if err = ctx.BindJSON(&req); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	err = logic.ConfigLogic.SetSystemConfiguration(req) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c *configApi) EsConfigReload(ctx *gin.Context) { | ||||
| 	errCheck(ctx, !logic.EsLogic.InitEs(), "Incorrect username or password!") | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (c *configApi) LogConfigReload(ctx *gin.Context, _ any) (err error) { | ||||
| 	return logic.LogLogicImpl.Init() | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package api | ||||
|  | ||||
| import ( | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/logic" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
| @@ -10,24 +11,25 @@ type file struct{} | ||||
|  | ||||
| var FileApi = new(file) | ||||
|  | ||||
| func (f *file) FilePathHandler(ctx *gin.Context) { | ||||
| 	path := getQueryString(ctx, "path") | ||||
| 	rOk(ctx, "Operation successful!", logic.FileLogic.GetFileAndDirByPath(path)) | ||||
| func (f *file) FilePathHandler(ctx *gin.Context, req model.FilePathHandlerReq) []model.FileStruct { | ||||
| 	return logic.FileLogic.GetFileAndDirByPath(req.Path) | ||||
| } | ||||
|  | ||||
| func (f *file) FileWriteHandler(ctx *gin.Context) { | ||||
| func (f *file) FileWriteHandler(ctx *gin.Context, _ any) (err error) { | ||||
| 	path := ctx.PostForm("filePath") | ||||
| 	fi, err := ctx.FormFile("data") | ||||
| 	errCheck(ctx, err != nil, "Read file data failed!") | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	fiReader, _ := fi.Open() | ||||
| 	err = logic.FileLogic.UpdateFileData(path, fiReader, fi.Size) | ||||
| 	errCheck(ctx, err != nil, "Update file data operation failed!") | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (f *file) FileReadHandler(ctx *gin.Context) { | ||||
| 	path := getQueryString(ctx, "filePath") | ||||
| 	bytes, err := logic.FileLogic.ReadFileFromPath(path) | ||||
| 	errCheck(ctx, err != nil, "Operation failed!") | ||||
| 	rOk(ctx, "Operation successful!", string(bytes)) | ||||
| func (f *file) FileReadHandler(ctx *gin.Context, req model.FileReadHandlerReq) any { | ||||
| 	bytes, err := logic.FileLogic.ReadFileFromPath(req.FilePath) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return string(bytes) | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,10 @@ | ||||
| package api | ||||
|  | ||||
| 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" | ||||
| @@ -15,23 +16,24 @@ type logApi struct{} | ||||
|  | ||||
| var LogApi = new(logApi) | ||||
|  | ||||
| func (a *logApi) GetLog(ctx *gin.Context) { | ||||
| 	req := bind[model.GetLogReq](ctx) | ||||
| func (a *logApi) GetLog(ctx *gin.Context, req model.GetLogReq) any { | ||||
| 	if isAdmin(ctx) { | ||||
| 		rOk(ctx, "Query successful!", logic.LogLogicImpl.Search(req, req.FilterName...)) | ||||
| 		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) | ||||
| 		}) | ||||
| 		if len(filterName) == 0 { | ||||
| 			filterName = processNameList | ||||
| 		} | ||||
| 		errCheck(ctx, len(filterName) == 0, "No information found!") | ||||
| 		rOk(ctx, "Query successful!", logic.LogLogicImpl.Search(req, filterName...)) | ||||
| 		if len(filterName) == 0 { | ||||
| 			return errors.New("no information found") | ||||
| 		} | ||||
| 		return logic.LogLogicImpl.Search(req, filterName...) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (a *logApi) GetRunningLog(ctx *gin.Context) { | ||||
| 	rOk(ctx, "Query successful!", logic.Loghandler.GetRunning()) | ||||
| func (a *logApi) GetRunningLog(ctx *gin.Context, _ any) int { | ||||
| 	return logic.Loghandler.GetRunning() | ||||
| } | ||||
|   | ||||
| @@ -11,14 +11,12 @@ var PermissionApi = new(permissionApi) | ||||
|  | ||||
| type permissionApi struct{} | ||||
|  | ||||
| func (p *permissionApi) EditPermssion(ctx *gin.Context) { | ||||
| 	req := bind[model.Permission](ctx) | ||||
| 	err := repository.PermissionRepository.EditPermssion(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (p *permissionApi) EditPermssion(ctx *gin.Context, req model.Permission) (err error) { | ||||
| 	return repository.PermissionRepository.EditPermssion(req) | ||||
| } | ||||
|  | ||||
| func (p *permissionApi) GetPermissionList(ctx *gin.Context) { | ||||
| 	result := repository.PermissionRepository.GetPermssionList(getQueryString(ctx, "account")) | ||||
| 	rOk(ctx, "Query successful!", result) | ||||
| func (p *permissionApi) GetPermissionList(ctx *gin.Context, req struct { | ||||
| 	Account string `form:"account" binding:"required"` | ||||
| }) any { | ||||
| 	return repository.PermissionRepository.GetPermssionList(req.Account) | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,15 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"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" | ||||
| 	"github.com/lzh-1625/go_process_manager/utils" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
| @@ -12,98 +18,126 @@ type procApi struct{} | ||||
|  | ||||
| var ProcApi = new(procApi) | ||||
|  | ||||
| func (p *procApi) CreateNewProcess(ctx *gin.Context) { | ||||
| 	req := bind[model.Process](ctx) | ||||
| func (p *procApi) CreateNewProcess(ctx *gin.Context, req model.Process) any { | ||||
| 	index, err := repository.ProcessRepository.AddProcessConfig(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	req.Uuid = index | ||||
| 	proc, err := logic.ProcessCtlLogic.NewProcess(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	logic.ProcessCtlLogic.AddProcess(req.Uuid, proc) | ||||
| 	rOk(ctx, "Operation successful!", gin.H{ | ||||
| 		"id": req.Uuid, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (p *procApi) DeleteNewProcess(ctx *gin.Context) { | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	logic.ProcessCtlLogic.KillProcess(uuid) | ||||
| 	logic.ProcessCtlLogic.DeleteProcess(uuid) | ||||
| 	err := repository.ProcessRepository.DeleteProcessConfig(uuid) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| } | ||||
|  | ||||
| func (p *procApi) KillProcess(ctx *gin.Context) { | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	err := logic.ProcessCtlLogic.KillProcess(uuid) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| } | ||||
|  | ||||
| func (p *procApi) StartProcess(ctx *gin.Context) { | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	prod, err := logic.ProcessCtlLogic.GetProcess(uuid) | ||||
| 	if err != nil { // 进程不存在则创建 | ||||
| 		proc, err := logic.ProcessCtlLogic.RunNewProcess(repository.ProcessRepository.GetProcessConfigById(uuid)) | ||||
| 		errCheck(ctx, err != nil, err) | ||||
| 		logic.ProcessCtlLogic.AddProcess(uuid, proc) | ||||
| 		rOk(ctx, "Operation successful!", nil) | ||||
| 		return | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	logic.ProcessCtlLogic.AddProcess(req.Uuid, proc) | ||||
| 	return gin.H{ | ||||
| 		"id": req.Uuid, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *procApi) DeleteNewProcess(ctx *gin.Context, req struct { | ||||
| 	Uuid int `form:"uuid" binding:"required"` | ||||
| }) (err error) { | ||||
| 	logic.ProcessCtlLogic.KillProcess(req.Uuid) | ||||
| 	logic.ProcessCtlLogic.DeleteProcess(req.Uuid) | ||||
| 	return repository.ProcessRepository.DeleteProcessConfig(req.Uuid) | ||||
| } | ||||
|  | ||||
| func (p *procApi) KillProcess(ctx *gin.Context, req struct { | ||||
| 	Uuid int `form:"uuid" binding:"required"` | ||||
| }) (err error) { | ||||
| 	return logic.ProcessCtlLogic.KillProcess(req.Uuid) | ||||
| } | ||||
|  | ||||
| func (p *procApi) StartProcess(ctx *gin.Context, req struct { | ||||
| 	Uuid int `form:"uuid" binding:"required"` | ||||
| }) (err error) { | ||||
| 	prod, err := logic.ProcessCtlLogic.GetProcess(req.Uuid) | ||||
| 	if err != nil { // 进程不存在则创建 | ||||
| 		proConfig, err := repository.ProcessRepository.GetProcessConfigById(req.Uuid) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		proc, err := logic.ProcessCtlLogic.RunNewProcess(proConfig) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		logic.ProcessCtlLogic.AddProcess(req.Uuid, proc) | ||||
| 		return nil | ||||
| 	} | ||||
| 	if prod.State.State == eum.ProcessStateStart || prod.State.State == eum.ProcessStateRunning { | ||||
| 		return errors.New("process is currently running") | ||||
| 	} | ||||
| 	errCheck(ctx, prod.State.State == 1, "The process is currently running.") | ||||
| 	prod.ResetRestartTimes() | ||||
| 	err = prod.Start() | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *procApi) StartAllProcess(ctx *gin.Context) { | ||||
| func (p *procApi) StartAllProcess(ctx *gin.Context, _ any) (err error) { | ||||
| 	if isAdmin(ctx) { | ||||
| 		logic.ProcessCtlLogic.ProcessStartAll() | ||||
| 	} else { | ||||
| 		logic.ProcessCtlLogic.ProcesStartAllByUsername(getUserName(ctx)) | ||||
| 	} | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *procApi) KillAllProcess(ctx *gin.Context) { | ||||
| func (p *procApi) KillAllProcess(ctx *gin.Context, _ any) (err error) { | ||||
| 	if isAdmin(ctx) { | ||||
| 		logic.ProcessCtlLogic.KillAllProcess() | ||||
| 	} else { | ||||
| 		logic.ProcessCtlLogic.KillAllProcessByUserName(getUserName(ctx)) | ||||
| 	} | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *procApi) GetProcessList(ctx *gin.Context) { | ||||
| func (p *procApi) GetProcessList(ctx *gin.Context, _ any) any { | ||||
| 	if isAdmin(ctx) { | ||||
| 		rOk(ctx, "Query successful!", logic.ProcessCtlLogic.GetProcessList()) | ||||
| 		return logic.ProcessCtlLogic.GetProcessList() | ||||
| 	} else { | ||||
| 		rOk(ctx, "Query successful!", logic.ProcessCtlLogic.GetProcessListByUser(getUserName(ctx))) | ||||
| 		return logic.ProcessCtlLogic.GetProcessListByUser(getUserName(ctx)) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *procApi) UpdateProcessConfig(ctx *gin.Context) { | ||||
| 	req := bind[model.Process](ctx) | ||||
| func (p *procApi) UpdateProcessConfig(ctx *gin.Context, req model.Process) (err error) { | ||||
| 	logic.ProcessCtlLogic.UpdateProcessConfig(req) | ||||
| 	err := repository.ProcessRepository.UpdateProcessConfig(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	err = repository.ProcessRepository.UpdateProcessConfig(req) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *procApi) GetProcessConfig(ctx *gin.Context) { | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	data := repository.ProcessRepository.GetProcessConfigById(uuid) | ||||
| 	errCheck(ctx, data.Uuid == 0, "No information found!") | ||||
| 	rOk(ctx, "Query successful!", data) | ||||
| func (p *procApi) GetProcessConfig(ctx *gin.Context, req struct { | ||||
| 	Uuid int `form:"uuid" binding:"required"` | ||||
| }) any { | ||||
| 	data, err := repository.ProcessRepository.GetProcessConfigById(req.Uuid) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return data | ||||
| } | ||||
|  | ||||
| func (p *procApi) ProcessControl(ctx *gin.Context) { | ||||
| func (p *procApi) ProcessControl(ctx *gin.Context, req struct { | ||||
| 	Uuid int `form:"uuid" binding:"required"` | ||||
| }) (err error) { | ||||
| 	user := getUserName(ctx) | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	proc, err := logic.ProcessCtlLogic.GetProcess(uuid) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	proc, err := logic.ProcessCtlLogic.GetProcess(req.Uuid) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	proc.ProcessControl(user) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *procApi) ProcessCreateShare(ctx *gin.Context, req model.ProcessShare) any { | ||||
| 	token := utils.UnwarpIgnore(uuid.NewRandom()).String() | ||||
| 	if err := repository.WsShare.AddShareData(model.WsShare{ | ||||
| 		ExpireTime: time.Now().Add(time.Minute * time.Duration(req.Minutes)), | ||||
| 		Write:      req.Write, | ||||
| 		Token:      token, | ||||
| 		Pid:        req.Pid, | ||||
| 		CreateBy:   getUserName(ctx), | ||||
| 	}); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return gin.H{ | ||||
| 		"token": token, | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -11,32 +11,26 @@ type pushApi struct{} | ||||
|  | ||||
| var PushApi = new(pushApi) | ||||
|  | ||||
| func (p *pushApi) GetPushList(ctx *gin.Context) { | ||||
| 	rOk(ctx, "Query successful!", repository.PushRepository.GetPushList()) | ||||
| func (p *pushApi) GetPushList(ctx *gin.Context, __ any) any { | ||||
| 	return repository.PushRepository.GetPushList() | ||||
| } | ||||
|  | ||||
| func (p *pushApi) GetPushById(ctx *gin.Context) { | ||||
| 	id := getQueryInt(ctx, "id") | ||||
| 	rOk(ctx, "Query successful!", repository.PushRepository.GetPushConfigById(id)) | ||||
| func (p *pushApi) GetPushById(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) any { | ||||
| 	return repository.PushRepository.GetPushConfigById(req.Id) | ||||
| } | ||||
|  | ||||
| func (p *pushApi) AddPushConfig(ctx *gin.Context) { | ||||
| 	req := bind[model.Push](ctx) | ||||
| 	err := repository.PushRepository.AddPushConfig(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (p *pushApi) AddPushConfig(ctx *gin.Context, req model.Push) (err error) { | ||||
| 	return repository.PushRepository.AddPushConfig(req) | ||||
| } | ||||
|  | ||||
| func (p *pushApi) UpdatePushConfig(ctx *gin.Context) { | ||||
| 	req := bind[model.Push](ctx) | ||||
| 	err := repository.PushRepository.UpdatePushConfig(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (p *pushApi) UpdatePushConfig(ctx *gin.Context, req model.Push) (err error) { | ||||
| 	return repository.PushRepository.UpdatePushConfig(req) | ||||
| } | ||||
|  | ||||
| func (p *pushApi) DeletePushConfig(ctx *gin.Context) { | ||||
| 	id := getQueryInt(ctx, "id") | ||||
| 	err := repository.PushRepository.DeletePushConfig(id) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (p *pushApi) DeletePushConfig(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) (err error) { | ||||
| 	return repository.PushRepository.DeletePushConfig(req.Id) | ||||
| } | ||||
|   | ||||
| @@ -12,62 +12,58 @@ type taskApi struct{} | ||||
|  | ||||
| var TaskApi = new(taskApi) | ||||
|  | ||||
| func (t *taskApi) CreateTask(ctx *gin.Context) { | ||||
| 	req := bind[model.Task](ctx) | ||||
| 	err := logic.TaskLogic.CreateTask(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) CreateTask(ctx *gin.Context, req model.Task) (err error) { | ||||
| 	return logic.TaskLogic.CreateTask(req) | ||||
| } | ||||
|  | ||||
| func (t *taskApi) GetTaskById(ctx *gin.Context) { | ||||
| 	result, err := repository.TaskRepository.GetTaskById(getQueryInt(ctx, "id")) | ||||
| 	errCheck(ctx, err != nil, "Query failed!") | ||||
| 	rOk(ctx, "Operation successful!", result) | ||||
| func (t *taskApi) GetTaskById(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) any { | ||||
| 	result, err := repository.TaskRepository.GetTaskById(req.Id) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| func (t *taskApi) GetTaskList(ctx *gin.Context) { | ||||
| 	result := logic.TaskLogic.GetAllTaskJob() | ||||
| 	rOk(ctx, "Operation successful!", result) | ||||
| func (t *taskApi) GetTaskList(ctx *gin.Context, _ any) any { | ||||
| 	return logic.TaskLogic.GetAllTaskJob() | ||||
| } | ||||
|  | ||||
| func (t *taskApi) DeleteTaskById(ctx *gin.Context) { | ||||
| 	err := logic.TaskLogic.DeleteTask(getQueryInt(ctx, "id")) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) DeleteTaskById(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) (err error) { | ||||
| 	return logic.TaskLogic.DeleteTask(req.Id) | ||||
|  | ||||
| } | ||||
|  | ||||
| func (t *taskApi) StartTask(ctx *gin.Context) { | ||||
| 	go logic.TaskLogic.RunTaskById(getQueryInt(ctx, "id")) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) StartTask(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) (err error) { | ||||
| 	go logic.TaskLogic.RunTaskById(req.Id) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (t *taskApi) StopTask(ctx *gin.Context) { | ||||
| 	errCheck(ctx, logic.TaskLogic.StopTaskJob(getQueryInt(ctx, "id")) != nil, "Operation failed!") | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) StopTask(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) (err error) { | ||||
| 	return logic.TaskLogic.StopTaskJob(req.Id) | ||||
| } | ||||
|  | ||||
| func (t *taskApi) EditTask(ctx *gin.Context) { | ||||
| 	req := bind[model.Task](ctx) | ||||
| 	err := logic.TaskLogic.EditTask(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) EditTask(ctx *gin.Context, req model.Task) (err error) { | ||||
| 	return logic.TaskLogic.EditTask(req) | ||||
| } | ||||
|  | ||||
| func (t *taskApi) EditTaskEnable(ctx *gin.Context) { | ||||
| 	req := bind[model.Task](ctx) | ||||
| 	err := logic.TaskLogic.EditTaskEnable(req.Id, req.Enable) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) EditTaskEnable(ctx *gin.Context, req model.Task) (err error) { | ||||
| 	return logic.TaskLogic.EditTaskEnable(req.Id, req.Enable) | ||||
| } | ||||
|  | ||||
| func (t *taskApi) RunTaskByKey(ctx *gin.Context) { | ||||
| 	err := logic.TaskLogic.RunTaskByKey(ctx.Param("key")) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) RunTaskByKey(ctx *gin.Context, _ any) (err error) { | ||||
| 	return logic.TaskLogic.RunTaskByKey(ctx.Param("key")) | ||||
| } | ||||
|  | ||||
| func (t *taskApi) CreateTaskApiKey(ctx *gin.Context) { | ||||
| 	err := logic.TaskLogic.CreateApiKey(getQueryInt(ctx, "id")) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (t *taskApi) CreateTaskApiKey(ctx *gin.Context, req struct { | ||||
| 	Id int `form:"id" binding:"required"` | ||||
| }) (err error) { | ||||
| 	return logic.TaskLogic.CreateApiKey(req.Id) | ||||
| } | ||||
|   | ||||
| @@ -1,8 +1,10 @@ | ||||
| package api | ||||
|  | ||||
| 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" | ||||
| @@ -16,57 +18,64 @@ var UserApi = new(userApi) | ||||
|  | ||||
| const DEFAULT_ROOT_PASSWORD = "root" | ||||
|  | ||||
| func (u *userApi) LoginHandler(ctx *gin.Context) { | ||||
| 	req := bind[map[string]string](ctx) | ||||
| 	account := req["account"] | ||||
| 	password := req["password"] | ||||
| 	errCheck(ctx, !u.checkLoginInfo(account, password), "Incorrect username or password!") | ||||
| 	token, err := utils.GenToken(account) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", gin.H{ | ||||
| func (u *userApi) LoginHandler(ctx *gin.Context, req model.LoginHandlerReq) any { | ||||
| 	if !u.checkLoginInfo(req.Account, req.Password) { | ||||
| 		return errors.New("incorrect username or password") | ||||
| 	} | ||||
| 	token, err := utils.GenerateToken(req.Account) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return gin.H{ | ||||
| 		"code":     0, | ||||
| 		"token":    token, | ||||
| 		"username": account, | ||||
| 		"role":     repository.UserRepository.GetUserByName(account).Role, | ||||
| 	}) | ||||
| 		"username": req.Account, | ||||
| 		"role":     repository.UserRepository.GetUserByName(req.Account).Role, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u *userApi) CreateUser(ctx *gin.Context) { | ||||
| 	req := bind[model.User](ctx) | ||||
| 	errCheck(ctx, req.Role == constants.ROLE_ROOT, "Creation of root accounts is forbidden!") | ||||
| 	errCheck(ctx, req.Account == constants.CONSOLE, "Operation failed!") | ||||
| 	errCheck(ctx, len(req.Password) < config.CF.UserPassWordMinLength, "Password is too short") | ||||
| 	err := repository.UserRepository.CreateUser(req) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (u *userApi) CreateUser(ctx *gin.Context, req model.User) (err error) { | ||||
| 	if req.Role == eum.RoleRoot { | ||||
| 		return errors.New("creation of root accounts is forbidden") | ||||
| 	} | ||||
| 	if req.Account == eum.Console { | ||||
| 		return errors.New("operation failed") | ||||
| 	} | ||||
| 	if len(req.Password) < config.CF.UserPassWordMinLength { | ||||
| 		return errors.New("password is too short") | ||||
| 	} | ||||
| 	err = repository.UserRepository.CreateUser(req) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (u *userApi) ChangePassword(ctx *gin.Context) { | ||||
| 	req := bind[model.User](ctx) | ||||
| func (u *userApi) ChangePassword(ctx *gin.Context, req model.User) (err error) { | ||||
| 	reqUser := getUserName(ctx) | ||||
| 	errCheck(ctx, getRole(ctx) != constants.ROLE_ROOT && req.Account != "", "Invalid parameters!") | ||||
| 	if getRole(ctx) != eum.RoleRoot && req.Account != "" { | ||||
| 		return errors.New("invalid parameters") | ||||
| 	} | ||||
| 	var userName string | ||||
| 	if req.Account != "" { | ||||
| 		userName = req.Account | ||||
| 	} else { | ||||
| 		userName = reqUser | ||||
| 	} | ||||
| 	errCheck(ctx, len(req.Password) < config.CF.UserPassWordMinLength, "Password is too short") | ||||
| 	err := repository.UserRepository.UpdatePassword(userName, req.Password) | ||||
| 	errCheck(ctx, err != nil, err) | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
|  | ||||
| 	if len(req.Password) < config.CF.UserPassWordMinLength { | ||||
| 		return errors.New("password is too short") | ||||
| 	} | ||||
| 	err = repository.UserRepository.UpdatePassword(userName, req.Password) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (u *userApi) DeleteUser(ctx *gin.Context) { | ||||
| 	account := getQueryString(ctx, "account") | ||||
| 	errCheck(ctx, account == "root", "Deletion of root accounts is forbidden!") | ||||
| 	err := repository.UserRepository.DeleteUser(account) | ||||
| 	errCheck(ctx, err != nil, "Deletion of root accounts failed!") | ||||
| 	rOk(ctx, "Operation successful!", nil) | ||||
| func (u *userApi) DeleteUser(ctx *gin.Context, req model.User) (err error) { | ||||
| 	if req.Account == "root" { | ||||
| 		return errors.New("deletion of root accounts is forbidden") | ||||
| 	} | ||||
| 	err = repository.UserRepository.DeleteUser(req.Account) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (u *userApi) GetUserList(ctx *gin.Context) { | ||||
| 	rOk(ctx, "Query successful!", repository.UserRepository.GetUserList()) | ||||
| func (u *userApi) GetUserList(ctx *gin.Context, _ any) any { | ||||
| 	return repository.UserRepository.GetUserList() | ||||
| } | ||||
|  | ||||
| func (u *userApi) checkLoginInfo(account, password string) bool { | ||||
| @@ -75,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 | ||||
| 	} | ||||
|   | ||||
| @@ -2,15 +2,17 @@ package api | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"strconv" | ||||
| 	"sync" | ||||
| 	"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/middle" | ||||
| 	"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" | ||||
| 	"github.com/lzh-1625/go_process_manager/utils" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"github.com/gorilla/websocket" | ||||
| @@ -46,24 +48,25 @@ var upgrader = websocket.Upgrader{ | ||||
| 	WriteBufferSize: 1024, | ||||
| } | ||||
|  | ||||
| func (w *wsApi) WebsocketHandle(ctx *gin.Context) { | ||||
| func (w *wsApi) WebsocketHandle(ctx *gin.Context, req model.WebsocketHandleReq) (err error) { | ||||
| 	reqUser := getUserName(ctx) | ||||
| 	uuid := getQueryInt(ctx, "uuid") | ||||
| 	proc, err := logic.ProcessCtlLogic.GetProcess(uuid) | ||||
| 	errCheck(ctx, err != nil, "Operation failed!") | ||||
| 	errCheck(ctx, proc.HasWsConn(reqUser), "A connection already exists; unable to establish a new one!") | ||||
| 	errCheck(ctx, proc.State.State != 1, "The process is currently running.") | ||||
| 	errCheck(ctx, proc.Control.Controller != reqUser && !proc.VerifyControl(), "Insufficient permissions; please check your access rights!") | ||||
| 	proc, err := logic.ProcessCtlLogic.GetProcess(req.Uuid) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if proc.HasWsConn(reqUser) { | ||||
| 		return errors.New("connection already exists") | ||||
| 	} | ||||
| 	if proc.Control.Controller != reqUser && !proc.VerifyControl() { | ||||
| 		return errors.New("insufficient permissions") | ||||
| 	} | ||||
| 	conn, err := upgrader.Upgrade(ctx.Writer, ctx.Request, nil) | ||||
| 	errCheck(ctx, err != nil, "WebSocket connection upgrade failed!") | ||||
|  | ||||
| 	log.Logger.AddAdditionalInfo("processName", proc.Name) | ||||
| 	log.Logger.AddAdditionalInfo("userName", reqUser) | ||||
| 	defer log.Logger.DeleteAdditionalInfo(2) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	log.Logger.Infow("ws连接成功") | ||||
|  | ||||
| 	proc.SetTerminalSize(utils.GetIntByString(ctx.Query("cols")), utils.GetIntByString(ctx.Query("rows"))) | ||||
| 	wsCtx, cancel := context.WithCancel(context.Background()) | ||||
| 	wci := &WsConnetInstance{ | ||||
| 		WsConnect:  conn, | ||||
| @@ -71,16 +74,16 @@ func (w *wsApi) WebsocketHandle(ctx *gin.Context) { | ||||
| 		wsLock:     sync.Mutex{}, | ||||
| 	} | ||||
| 	proc.ReadCache(wci) | ||||
| 	w.startWsConnect(wci, cancel, proc, hasOprPermission(ctx, uuid, constants.OPERATION_TERMINAL_WRITE)) | ||||
| 	proc.AddConn(reqUser, wci) | ||||
| 	defer middle.ProcessWaitCond.Trigger() | ||||
| 	defer proc.DeleteConn(reqUser) | ||||
| 	if proc.State.State == eum.ProcessStateRunning { | ||||
| 		proc.SetTerminalSize(req.Cols, req.Rows) | ||||
| 		w.startWsConnect(wci, cancel, proc, hasOprPermission(ctx, req.Uuid, eum.OperationTerminalWrite)) | ||||
| 		proc.AddConn(reqUser, wci) | ||||
| 		defer proc.DeleteConn(reqUser) | ||||
| 	} | ||||
| 	conn.SetCloseHandler(func(_ int, _ string) error { | ||||
| 		middle.ProcessWaitCond.Trigger() | ||||
| 		cancel() | ||||
| 		return nil | ||||
| 	}) | ||||
| 	middle.ProcessWaitCond.Trigger() | ||||
| 	select { | ||||
| 	case <-proc.StopChan: | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "进程已停止,强制断开ws连接") | ||||
| @@ -90,6 +93,67 @@ func (w *wsApi) WebsocketHandle(ctx *gin.Context) { | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "tcp连接建立已被关闭") | ||||
| 	} | ||||
| 	conn.Close() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (w *wsApi) WebsocketShareHandle(ctx *gin.Context, req model.WebsocketHandleReq) (err error) { | ||||
| 	data, err := repository.WsShare.GetWsShareDataByToken(req.Token) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if data.ExpireTime.Before(time.Now()) { | ||||
| 		return errors.New("share expired") | ||||
| 	} | ||||
| 	proc, err := logic.ProcessCtlLogic.GetProcess(data.Pid) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	guestName := "guest-" + strconv.Itoa(int(data.ID)) // 构造访客用户名 | ||||
| 	if proc.HasWsConn(guestName) { | ||||
| 		return errors.New("connection already exists") | ||||
| 	} | ||||
| 	if proc.State.State != eum.ProcessStateRunning { | ||||
| 		return errors.New("process not is running") | ||||
| 	} | ||||
| 	if !proc.VerifyControl() { | ||||
| 		return errors.New("insufficient permissions") | ||||
| 	} | ||||
| 	conn, err := upgrader.Upgrade(ctx.Writer, ctx.Request, nil) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	log.Logger.Infow("ws连接成功") | ||||
| 	data.UpdatedAt = time.Now() | ||||
| 	repository.WsShare.Edit(data) | ||||
|  | ||||
| 	proc.SetTerminalSize(req.Cols, req.Rows) | ||||
| 	wsCtx, cancel := context.WithCancel(context.Background()) | ||||
| 	wci := &WsConnetInstance{ | ||||
| 		WsConnect:  conn, | ||||
| 		CancelFunc: cancel, | ||||
| 		wsLock:     sync.Mutex{}, | ||||
| 	} | ||||
| 	proc.ReadCache(wci) | ||||
| 	w.startWsConnect(wci, cancel, proc, data.Write) | ||||
| 	proc.AddConn(guestName, wci) | ||||
| 	defer proc.DeleteConn(guestName) | ||||
| 	conn.SetCloseHandler(func(_ int, _ string) error { | ||||
| 		cancel() | ||||
| 		return nil | ||||
| 	}) | ||||
| 	select { | ||||
| 	case <-proc.StopChan: | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "进程已停止,强制断开ws连接") | ||||
| 	case <-time.After(time.Minute * time.Duration(config.CF.TerminalConnectTimeout)): | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "连接时间超过最大时长限制") | ||||
| 	case <-wsCtx.Done(): | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "tcp连接建立已被关闭") | ||||
| 	case <-time.After(time.Until(data.ExpireTime)): | ||||
| 		log.Logger.Infow("ws连接断开", "操作类型", "分享时间已结束") | ||||
| 	} | ||||
| 	conn.Close() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (w *wsApi) startWsConnect(wci *WsConnetInstance, cancel context.CancelFunc, proc logic.Process, write bool) { | ||||
| @@ -132,3 +196,11 @@ func (w *wsApi) startWsConnect(wci *WsConnetInstance, cancel context.CancelFunc, | ||||
| 	}() | ||||
|  | ||||
| } | ||||
|  | ||||
| func GetWsShareList(ctx *gin.Context, _ any) any { | ||||
| 	return logic.WsSahreLogic.GetWsShareList() | ||||
| } | ||||
|  | ||||
| func DeleteWsShareById(ctx *gin.Context, _ any) any { | ||||
| 	return logic.WsSahreLogic.DeleteById(ctx.GetInt("id")) | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
| 	} | ||||
| } | ||||
| @@ -20,7 +20,7 @@ var ( | ||||
|  | ||||
| func InitLogHandle() { | ||||
| 	Loghandler.antsPool, _ = ants.NewPool(config.CF.LogHandlerPoolSize, ants.WithNonblocking(true), ants.WithExpiryDuration(3*time.Second), ants.WithPanicHandler(func(i interface{}) { | ||||
| 		log.Logger.Error("es消息储存失败") | ||||
| 		log.Logger.Warnw("日志储存失败", "err", i) | ||||
| 	})) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -2,55 +2,16 @@ package logic | ||||
|  | ||||
| import ( | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
| 	"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/search" | ||||
|  | ||||
| 	_ "github.com/lzh-1625/go_process_manager/internal/app/search/bleve" | ||||
| 	_ "github.com/lzh-1625/go_process_manager/internal/app/search/es" | ||||
| 	_ "github.com/lzh-1625/go_process_manager/internal/app/search/sqlite" | ||||
| ) | ||||
|  | ||||
| type LogLogic interface { | ||||
| 	Search(req model.GetLogReq, filterProcessName ...string) model.LogResp | ||||
| 	Insert(log string, processName string, using string, ts int64) | ||||
| } | ||||
|  | ||||
| var LogLogicImpl LogLogic | ||||
| var LogLogicImpl search.LogLogic | ||||
|  | ||||
| func InitLog() { | ||||
| 	if config.CF.EsEnable { | ||||
| 		LogLogicImpl = LogEs | ||||
| 	} else { | ||||
| 		LogLogicImpl = LogSqlite | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type logSqlite struct{} | ||||
|  | ||||
| var LogSqlite = new(logSqlite) | ||||
|  | ||||
| func (l *logSqlite) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp { | ||||
| 	req.FilterName = filterProcessName | ||||
| 	data, total := repository.LogRepository.SearchLog(req) | ||||
| 	return model.LogResp{ | ||||
| 		Data:  data, | ||||
| 		Total: total, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (l *logSqlite) Insert(log string, processName string, using string, ts int64) { | ||||
| 	repository.LogRepository.InsertLog(model.ProcessLog{ | ||||
| 		Log:   log, | ||||
| 		Name:  processName, | ||||
| 		Using: using, | ||||
| 		Time:  ts, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| type logEs struct{} | ||||
|  | ||||
| var LogEs = new(logEs) | ||||
|  | ||||
| func (l *logEs) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp { | ||||
| 	return EsLogic.Search(req, filterProcessName...) | ||||
| } | ||||
|  | ||||
| func (l *logEs) Insert(log string, processName string, using string, ts int64) { | ||||
| 	EsLogic.Insert(log, processName, using, ts) | ||||
| 	LogLogicImpl = search.GetSearchImpl(config.CF.StorgeType) | ||||
| 	LogLogicImpl.Init() | ||||
| } | ||||
|   | ||||
| @@ -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,13 +28,13 @@ type Process interface { | ||||
| 	doOnInit() | ||||
| 	doOnKilled() | ||||
| 	Start() error | ||||
| 	Type() constants.TerminalType | ||||
| 	Type() eum.TerminalType | ||||
| 	SetTerminalSize(int, int) | ||||
| } | ||||
|  | ||||
| type ProcessBase struct { | ||||
| 	Process | ||||
| 	p            *os.Process | ||||
| 	op           *os.Process | ||||
| 	Name         string | ||||
| 	Pid          int | ||||
| 	StartCommand []string | ||||
| @@ -49,7 +50,7 @@ type ProcessBase struct { | ||||
| 	Config struct { | ||||
| 		AutoRestart       bool | ||||
| 		compulsoryRestart bool | ||||
| 		PushIds           []int | ||||
| 		PushIds           []int64 | ||||
| 		logReport         bool | ||||
| 		cgroupEnable      bool | ||||
| 		memoryLimit       *float32 | ||||
| @@ -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 | ||||
| @@ -84,7 +85,7 @@ type ConnectInstance interface { | ||||
| } | ||||
|  | ||||
| func (p *ProcessBase) watchDog() { | ||||
| 	state, _ := p.p.Wait() | ||||
| 	state, _ := p.op.Wait() | ||||
| 	if p.cgroup.enable && p.cgroup.delete != nil { | ||||
| 		err := p.cgroup.delete() | ||||
| 		if err != nil { | ||||
| @@ -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("进程重启次数达到上限") | ||||
| } | ||||
| @@ -128,7 +129,7 @@ func (p *ProcessBase) pInit() { | ||||
| 	p.State.manualStopFlag = false | ||||
| 	p.State.startTime = time.Now() | ||||
| 	p.ws = make(map[string]ConnectInstance) | ||||
| 	p.Pid = p.p.Pid | ||||
| 	p.Pid = p.op.Pid | ||||
| 	p.doOnInit() | ||||
| 	p.InitPerformanceStatus() | ||||
| 	p.initPsutil() | ||||
| @@ -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(), ";") | ||||
| } | ||||
| @@ -177,12 +192,14 @@ func (p *ProcessBase) AddConn(user string, c ConnectInstance) { | ||||
| 	p.wsLock.Lock() | ||||
| 	defer p.wsLock.Unlock() | ||||
| 	p.ws[user] = c | ||||
| 	middle.ProcessWaitCond.Trigger() | ||||
| } | ||||
|  | ||||
| func (p *ProcessBase) DeleteConn(user string) { | ||||
| 	p.wsLock.Lock() | ||||
| 	defer p.wsLock.Unlock() | ||||
| 	delete(p.ws, user) | ||||
| 	middle.ProcessWaitCond.Trigger() | ||||
| } | ||||
|  | ||||
| func (p *ProcessBase) logReportHandler(log string) { | ||||
| @@ -216,7 +233,7 @@ func (p *ProcessBase) VerifyControl() bool { | ||||
| func (p *ProcessBase) setProcessConfig(pconfig model.Process) { | ||||
| 	p.Config.AutoRestart = pconfig.AutoRestart | ||||
| 	p.Config.logReport = pconfig.LogReport | ||||
| 	p.Config.PushIds = utils.JsonStrToStruct[[]int](pconfig.PushIds) | ||||
| 	p.Config.PushIds = utils.JsonStrToStruct[[]int64](pconfig.PushIds) | ||||
| 	p.Config.compulsoryRestart = pconfig.CompulsoryRestart | ||||
| 	p.Config.cgroupEnable = pconfig.CgroupEnable | ||||
| 	p.Config.memoryLimit = pconfig.MemoryLimit | ||||
| @@ -261,13 +278,11 @@ func (p *ProcessBase) monitorHanler() { | ||||
| 	if !p.monitor.enable { | ||||
| 		return | ||||
| 	} | ||||
| 	log.Logger.AddAdditionalInfo("name", p.Name) | ||||
| 	log.Logger.AddAdditionalInfo("pid", p.Pid) | ||||
| 	defer log.Logger.Infow("性能监控结束") | ||||
| 	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,7 +321,11 @@ func (p *ProcessBase) initPsutil() { | ||||
| } | ||||
|  | ||||
| func (p *ProcessBase) Kill() error { | ||||
| 	p.p.Signal(syscall.SIGINT) | ||||
| 	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: | ||||
| 		{ | ||||
| @@ -315,7 +334,7 @@ func (p *ProcessBase) Kill() error { | ||||
| 	case <-time.After(time.Second * time.Duration(config.CF.KillWaitTime)): | ||||
| 		{ | ||||
| 			log.Logger.Debugw("进程kill超时,强制停止进程", "name", p.Name) | ||||
| 			return p.p.Kill() | ||||
| 			return p.op.Kill() | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -1,3 +1,6 @@ | ||||
| //go:build windows | ||||
| // +build windows | ||||
|  | ||||
| package logic | ||||
|  | ||||
| import "github.com/lzh-1625/go_process_manager/log" | ||||
|   | ||||
| @@ -7,7 +7,8 @@ import ( | ||||
| 	"strings" | ||||
| 	"sync" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/constants" | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
| 	"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" | ||||
| @@ -36,21 +37,17 @@ 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() | ||||
| } | ||||
|  | ||||
| func (p *processCtlLogic) GetProcess(uuid int) (*ProcessBase, error) { | ||||
| 	process, ok := p.processMap.Load(uuid) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("进程获取失败") | ||||
| 		return nil, errors.New("process not exist") | ||||
| 	} | ||||
| 	result, ok := process.(*ProcessBase) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("进程类型错误") | ||||
| 		return nil, errors.New("process type error") | ||||
|  | ||||
| 	} | ||||
| 	return result, nil | ||||
| @@ -60,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 | ||||
| @@ -75,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) | ||||
| @@ -113,22 +106,25 @@ func (p *processCtlLogic) getProcessInfoList(processConfiglist []model.Process) | ||||
| 			Name: v.Name, | ||||
| 			Uuid: v.Uuid, | ||||
| 		} | ||||
| 		if value, ok := p.processMap.Load(v.Uuid); ok { | ||||
| 			process := value.(*ProcessBase) | ||||
| 			pi.State.Info = process.State.Info | ||||
| 			pi.State.State = process.State.State | ||||
| 			pi.StartTime = process.GetStartTimeFormat() | ||||
| 			pi.User = process.GetUserString() | ||||
| 			pi.Usage.Cpu = process.performanceStatus.cpu | ||||
| 			pi.Usage.CpuCapacity = float64(runtime.NumCPU()) * 100.0 | ||||
| 			pi.Usage.Mem = process.performanceStatus.mem | ||||
| 			pi.Usage.MemCapacity = float64(utils.UnwarpIgnore(mem.VirtualMemory()).Total >> 10) | ||||
| 			pi.Usage.Time = process.performanceStatus.time | ||||
| 			pi.TermType = process.Type() | ||||
| 			pi.CgroupEnable = process.Config.cgroupEnable | ||||
| 			pi.CpuLimit = process.Config.cpuLimit | ||||
| 			pi.MemoryLimit = process.Config.memoryLimit | ||||
| 		process, err := p.GetProcess(v.Uuid) | ||||
| 		if err != nil { | ||||
| 			continue | ||||
| 		} | ||||
| 		pi.State.Info = process.State.Info | ||||
| 		pi.State.State = process.State.State | ||||
| 		pi.StartTime = process.GetStartTimeFormat() | ||||
| 		pi.User = process.GetUserString() | ||||
| 		pi.Usage.Cpu = process.performanceStatus.cpu | ||||
| 		pi.Usage.Mem = process.performanceStatus.mem | ||||
| 		if config.CF.PerformanceCapacityDisplay { | ||||
| 			pi.Usage.CpuCapacity = float64(runtime.NumCPU()) * 100.0 | ||||
| 			pi.Usage.MemCapacity = float64(utils.UnwarpIgnore(mem.VirtualMemory()).Total >> 10) | ||||
| 		} | ||||
| 		pi.Usage.Time = process.performanceStatus.time | ||||
| 		pi.TermType = process.Type() | ||||
| 		pi.CgroupEnable = process.Config.cgroupEnable | ||||
| 		pi.CpuLimit = process.Config.cpuLimit | ||||
| 		pi.MemoryLimit = process.Config.memoryLimit | ||||
| 		processInfoList = append(processInfoList, pi) | ||||
| 	} | ||||
| 	return processInfoList | ||||
| @@ -146,7 +142,10 @@ func (p *processCtlLogic) ProcessStartAll() { | ||||
| } | ||||
|  | ||||
| func (p *processCtlLogic) RunPrcessById(id int) (*ProcessBase, error) { | ||||
| 	config := repository.ProcessRepository.GetProcessConfigById(id) | ||||
| 	config, err := repository.ProcessRepository.GetProcessConfigById(id) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	proc, err := p.RunNewProcess(config) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Warnw("初始化启动进程失败", config.Name, "name", "err", err) | ||||
| @@ -159,7 +158,6 @@ func (p *processCtlLogic) RunPrcessById(id int) (*ProcessBase, error) { | ||||
| func (p *processCtlLogic) ProcessInit() { | ||||
| 	config := repository.ProcessRepository.GetAllProcessConfig() | ||||
| 	for _, v := range config { | ||||
|  | ||||
| 		proc, err := p.NewProcess(v) | ||||
| 		if err != nil { | ||||
| 			log.Logger.Warnw("初始化启动进程失败", v.Name, "name", "err", err) | ||||
| @@ -177,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) { | ||||
| @@ -205,7 +203,7 @@ func (p *processCtlLogic) UpdateProcessConfig(config model.Process) error { | ||||
| 	} | ||||
| 	defer result.Lock.Unlock() | ||||
| 	result.Config.logReport = config.LogReport | ||||
| 	result.Config.PushIds = utils.JsonStrToStruct[[]int](config.PushIds) | ||||
| 	result.Config.PushIds = utils.JsonStrToStruct[[]int64](config.PushIds) | ||||
| 	result.Config.cgroupEnable = config.CgroupEnable | ||||
| 	result.Config.memoryLimit = config.MemoryLimit | ||||
| 	result.Config.cpuLimit = config.CpuLimit | ||||
| @@ -219,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("终端类型错误") | ||||
|   | ||||
| @@ -6,8 +6,9 @@ import ( | ||||
| 	"os/exec" | ||||
| 	"strings" | ||||
|  | ||||
| 	"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" | ||||
| @@ -25,22 +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() { | ||||
| 		log.Logger.DeleteAdditionalInfo(1) | ||||
| 		if err != nil { | ||||
| 			p.Config.AutoRestart = false | ||||
| 			p.SetState(constants.PROCESS_WARNNING) | ||||
| 			p.SetState(eum.ProcessStateWarnning) | ||||
| 			p.State.Info = "进程启动失败:" + err.Error() | ||||
| 		} | ||||
| 	}() | ||||
| 	log.Logger.AddAdditionalInfo("进程名称", p.Name) | ||||
| 	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 | ||||
| @@ -58,7 +57,7 @@ func (p *ProcessPty) Start() (err error) { | ||||
| 	}) | ||||
| 	p.pty = pf | ||||
| 	log.Logger.Infow("进程启动成功", "进程名称", p.Name, "重启次数", p.State.restartTimes) | ||||
| 	p.p = cmd.Process | ||||
| 	p.op = cmd.Process | ||||
| 	p.pInit() | ||||
| 	p.push("进程启动成功") | ||||
| 	return nil | ||||
| @@ -115,7 +114,9 @@ func (p *ProcessPty) readInit() { | ||||
| } | ||||
|  | ||||
| func (p *ProcessPty) ReadCache(ws ConnectInstance) { | ||||
| 	ws.Write(p.cacheBytesBuf.Bytes()) | ||||
| 	if p.cacheBytesBuf != nil { | ||||
| 		ws.Write(p.cacheBytesBuf.Bytes()) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p *ProcessPty) bufHanle(b []byte) { | ||||
| @@ -135,7 +136,7 @@ func (p *ProcessPty) doOnInit() { | ||||
| func NewProcessPty(pconfig model.Process) *ProcessBase { | ||||
| 	p := ProcessBase{ | ||||
| 		Name:         pconfig.Name, | ||||
| 		StartCommand: strings.Split(pconfig.Cmd, " "), | ||||
| 		StartCommand: utils.UnwarpIgnore(shlex.Split(pconfig.Cmd)), | ||||
| 		WorkDir:      pconfig.Cwd, | ||||
| 	} | ||||
| 	processPty := ProcessPty{ | ||||
|   | ||||
| @@ -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,22 +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() { | ||||
| 		log.Logger.DeleteAdditionalInfo(1) | ||||
| 		if err != nil { | ||||
| 			p.Config.AutoRestart = false | ||||
| 			p.SetState(constants.PROCESS_WARNNING) | ||||
| 			p.SetState(eum.ProcessStateWarnning) | ||||
| 			p.State.Info = "进程启动失败:" + err.Error() | ||||
| 		} | ||||
| 	}() | ||||
| 	log.Logger.AddAdditionalInfo("进程名称", p.Name) | ||||
| 	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 | ||||
| @@ -61,13 +60,18 @@ func (p *ProcessPty) Start() (err error) { | ||||
| 		log.Logger.Errorw("进程启动失败", "err", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	p.p, err = os.FindProcess(pid) | ||||
| 	p.op, err = os.FindProcess(pid) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Errorw("进程启动失败", "err", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	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,12 +2,14 @@ package logic | ||||
|  | ||||
| import ( | ||||
| 	"bufio" | ||||
| 	"errors" | ||||
| 	"io" | ||||
| 	"os/exec" | ||||
| 	"strings" | ||||
|  | ||||
| 	"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" | ||||
| @@ -20,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) { | ||||
| @@ -38,16 +40,14 @@ func (p *ProcessStd) Write(input string) (err error) { | ||||
|  | ||||
| func (p *ProcessStd) Start() (err error) { | ||||
| 	defer func() { | ||||
| 		log.Logger.DeleteAdditionalInfo(1) | ||||
| 		if err != nil { | ||||
| 			p.Config.AutoRestart = false | ||||
| 			p.SetState(constants.PROCESS_WARNNING) | ||||
| 			p.SetState(eum.ProcessStateWarnning) | ||||
| 			p.State.Info = "进程启动失败:" + err.Error() | ||||
| 		} | ||||
| 	}() | ||||
| 	log.Logger.AddAdditionalInfo("进程名称", p.Name) | ||||
| 	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 | ||||
| @@ -72,8 +72,13 @@ func (p *ProcessStd) Start() (err error) { | ||||
| 		return err | ||||
| 	} | ||||
| 	log.Logger.Infow("进程启动成功", "重启次数", p.State.restartTimes) | ||||
| 	p.p = cmd.Process | ||||
| 	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 | ||||
| } | ||||
| @@ -135,7 +140,7 @@ func (p *ProcessStd) Read() string { | ||||
| func NewProcessStd(pconfig model.Process) *ProcessBase { | ||||
| 	p := ProcessBase{ | ||||
| 		Name:         pconfig.Name, | ||||
| 		StartCommand: strings.Split(pconfig.Cmd, " "), | ||||
| 		StartCommand: utils.UnwarpIgnore(shlex.Split(pconfig.Cmd)), | ||||
| 		WorkDir:      pconfig.Cwd, | ||||
| 	} | ||||
| 	processStd := ProcessStd{ | ||||
|   | ||||
| @@ -19,7 +19,7 @@ var PushLogic = &pushLogic{ | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| func (p *pushLogic) Push(ids []int, placeholders map[string]string) { | ||||
| func (p *pushLogic) Push(ids []int64, placeholders map[string]string) { | ||||
| 	pl := repository.PushRepository.GetPushConfigByIds(ids) | ||||
| 	for _, v := range pl { | ||||
| 		if v.Enable { | ||||
|   | ||||
| @@ -2,57 +2,67 @@ package logic | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
| 	"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" | ||||
| 	"github.com/robfig/cron/v3" | ||||
| ) | ||||
|  | ||||
| func (t *taskLogic) RunTaskById(id int) error { | ||||
| 	task, err := t.getTaskJob(id) | ||||
| 	if err != nil { | ||||
| 		return errors.New("id不存在") | ||||
| 	} | ||||
| 	if task.Running { | ||||
| 		return errors.New("task is running") | ||||
| 	} | ||||
| 	ctx, cancel := context.WithCancel(context.Background()) | ||||
| 	defer cancel() | ||||
| 	task.Cancel = cancel | ||||
| 	t.run(ctx, task) | ||||
| 	return nil | ||||
| type TaskJob struct { | ||||
| 	Cron       *cron.Cron         `json:"-"` | ||||
| 	TaskConfig *model.Task        `json:"task"` | ||||
| 	Running    bool               `json:"running"` | ||||
| 	Cancel     context.CancelFunc `json:"-"` | ||||
| 	StartTime  time.Time          `json:"startTime"` | ||||
| 	EndTime    time.Time          `json:"endTime"` | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) run(ctx context.Context, data *model.TaskJob) { | ||||
| 	data.Running = true | ||||
| func NewTaskJob(data model.Task) (*TaskJob, error) { | ||||
| 	tj := &TaskJob{ | ||||
| 		TaskConfig: &data, | ||||
| 		StartTime:  time.Now(), | ||||
| 	} | ||||
| 	if data.Enable && data.CronExpression != "" { | ||||
| 		err := tj.InitCronHandle() | ||||
| 		if err != nil { | ||||
| 			log.Logger.Warnw("定时任务启动失败", "err", err, "task", data.Id) | ||||
| 		} | ||||
| 	} | ||||
| 	return tj, nil | ||||
| } | ||||
|  | ||||
| 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() { | ||||
| 		data.Running = false | ||||
| 		t.Running = false | ||||
| 		middle.TaskWaitCond.Trigger() | ||||
| 	}() | ||||
| 	log.Logger.AddAdditionalInfo("taskId", data.Task.Id) | ||||
| 	defer log.Logger.DeleteAdditionalInfo(1) | ||||
| 	var ok bool | ||||
| 	// 判断条件是否满足 | ||||
| 	if data.Task.Condition == constants.PASS { | ||||
| 	if t.TaskConfig.Condition == eum.TaskCondPass { | ||||
| 		ok = true | ||||
| 	} else { | ||||
| 		proc, err := ProcessCtlLogic.GetProcess(data.Task.OperationTarget) | ||||
| 		proc, err := ProcessCtlLogic.GetProcess(t.TaskConfig.OperationTarget) | ||||
| 		if err != nil { | ||||
| 			return | ||||
| 		} | ||||
| 		ok = conditionHandle[data.Task.Condition](data.Task, proc) | ||||
| 		ok = conditionHandle[t.TaskConfig.Condition](t.TaskConfig, proc) | ||||
| 	} | ||||
| 	log.Logger.Debugw("任务条件判断", "pass", ok) | ||||
| 	if !ok { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	proc, err := ProcessCtlLogic.GetProcess(data.Task.OperationTarget) | ||||
| 	proc, err := ProcessCtlLogic.GetProcess(t.TaskConfig.OperationTarget) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Debugw("不存在该进程,结束任务") | ||||
| 		return | ||||
| @@ -60,98 +70,67 @@ func (t *taskLogic) run(ctx context.Context, data *model.TaskJob) { | ||||
|  | ||||
| 	// 执行操作 | ||||
| 	log.Logger.Infow("任务开始执行") | ||||
| 	if !OperationHandle[data.Task.Operation](data.Task, proc) { | ||||
| 	if !OperationHandle[t.TaskConfig.Operation](t.TaskConfig, proc) { | ||||
| 		log.Logger.Errorw("任务执行失败") | ||||
| 		return | ||||
| 	} | ||||
| 	log.Logger.Infow("任务执行成功", "target", data.Task.OperationTarget) | ||||
| 	log.Logger.Infow("任务执行成功", "target", t.TaskConfig.OperationTarget) | ||||
|  | ||||
| 	if data.Task.NextId != nil { | ||||
| 		nextTask, err := t.getTaskJob(*data.Task.NextId) | ||||
| 	if t.TaskConfig.NextId != nil { | ||||
| 		nextTask, err := TaskLogic.getTaskJob(*t.TaskConfig.NextId) | ||||
| 		if err != nil { | ||||
| 			log.Logger.Errorw("无法获取到下一个节点,结束任务", "nextId", data.Task.NextId) | ||||
| 			log.Logger.Errorw("无法获取到下一个节点,结束任务", "nextId", t.TaskConfig.NextId) | ||||
| 			return | ||||
| 		} | ||||
| 		select { | ||||
| 		case <-ctx.Done(): | ||||
| 			log.Logger.Infow("任务流被手动结束") | ||||
| 		default: | ||||
| 			log.Logger.Debugw("执行下一个节点", "nextId", *data.Task.NextId) | ||||
| 			log.Logger.Debugw("执行下一个节点", "nextId", *t.TaskConfig.NextId) | ||||
| 			if nextTask.Running { | ||||
| 				log.Logger.Errorw("下一个节点已在运行,结束任务", "nextId", data.Task.NextId) | ||||
| 				log.Logger.Errorw("下一个节点已在运行,结束任务", "nextId", t.TaskConfig.NextId) | ||||
| 				return | ||||
| 			} | ||||
| 			t.run(ctx, nextTask) | ||||
| 			nextTask.Run(ctx) | ||||
| 		} | ||||
| 	} else { | ||||
| 		log.Logger.Infow("任务流结束") | ||||
| 	} | ||||
| 	EventLogic.Create(t.TaskConfig.Name, eum.EventProcessStop, "traceId", ctx.Value(eum.CtxTaskTraceId{})) | ||||
| } | ||||
|  | ||||
| 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 | ||||
| 	}, | ||||
| 	constants.NOT_RUNNING: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		return proc.State.State != 1 | ||||
| 	}, | ||||
| 	constants.EXCEPTION: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		return proc.State.State == 2 | ||||
| 	}, | ||||
| func (t *TaskJob) InitCronHandle() error { | ||||
| 	if _, err := cron.ParseStandard(t.TaskConfig.CronExpression); err != nil { // cron表达式校验 | ||||
| 		log.Logger.Errorw("cron解析失败", "cron", t.TaskConfig.CronExpression, "err", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	c := cron.New() | ||||
| 	_, err := c.AddFunc(t.TaskConfig.CronExpression, func() { | ||||
| 		log.Logger.Infow("定时任务启动") | ||||
| 		if t.Running { | ||||
| 			log.Logger.Infow("任务已在运行,跳过当前任务") | ||||
| 			return | ||||
| 		} | ||||
| 		ctx, cancel := context.WithCancel(context.Background()) | ||||
| 		defer cancel() | ||||
| 		t.Cancel = cancel | ||||
| 		t.Run(ctx) | ||||
| 		log.Logger.Infow("定时任务结束") | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	c.Start() | ||||
| 	t.Cron = c | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // 执行操作,返回结果是否成功 | ||||
| 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("进程已在运行") | ||||
| 			return false | ||||
| 		} | ||||
| 		go proc.Start() | ||||
| 		return true | ||||
| 	}, | ||||
|  | ||||
| 	constants.TASK_START_WAIT_DONE: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		if proc.State.State == 1 { | ||||
| 			log.Logger.Debugw("进程已在运行") | ||||
| 			return false | ||||
| 		} | ||||
| 		if err := proc.Start(); err != nil { | ||||
| 			log.Logger.Debugw("进程启动失败") | ||||
| 			return false | ||||
| 		} | ||||
| 		select { | ||||
| 		case <-proc.StopChan: | ||||
| 			log.Logger.Debugw("进程停止,任务完成") | ||||
| 			return true | ||||
| 		case <-time.After(time.Second * time.Duration(config.CF.TaskTimeout)): | ||||
| 			log.Logger.Errorw("任务超时") | ||||
| 			return false | ||||
| 		} | ||||
| 	}, | ||||
|  | ||||
| 	constants.TASK_STOP: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		if proc.State.State != 1 { | ||||
| 			log.Logger.Debugw("进程未在运行") | ||||
| 			return false | ||||
| 		} | ||||
| 		log.Logger.Debugw("异步停止任务") | ||||
| 		proc.State.manualStopFlag = true | ||||
| 		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("进程未在运行") | ||||
| 			return false | ||||
| 		} | ||||
| 		log.Logger.Debugw("停止任务并等待结束") | ||||
| 		proc.State.manualStopFlag = true | ||||
| 		return proc.Kill() == nil | ||||
| 	}, | ||||
| func (t *TaskJob) EditStatus(status bool) error { | ||||
| 	if t.Cron != nil && !status { | ||||
| 		t.Cron.Stop() | ||||
| 	} else if err := t.InitCronHandle(); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	t.TaskConfig.Enable = status | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
							
								
								
									
										76
									
								
								internal/app/logic/task_exec.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								internal/app/logic/task_exec.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,76 @@ | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
| 	"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[eum.Condition]conditionFunc{ | ||||
| 	eum.TaskCondRunning: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		return proc.State.State == eum.ProcessStateRunning | ||||
| 	}, | ||||
| 	eum.TaskCondNotRunning: func(data *model.Task, proc *ProcessBase) bool { | ||||
| 		return proc.State.State != eum.ProcessStateRunning && proc.State.State != eum.ProcessStateStart | ||||
| 	}, | ||||
| 	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[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 | ||||
| 		} | ||||
| 		proc.Start() | ||||
| 		return true | ||||
| 	}, | ||||
|  | ||||
| 	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("进程启动失败", "proc", proc.Name) | ||||
| 			return false | ||||
| 		} | ||||
| 		select { | ||||
| 		case <-proc.StopChan: | ||||
| 			log.Logger.Debugw("进程停止,任务完成", "proc", proc.Name) | ||||
| 			return true | ||||
| 		case <-time.After(time.Second * time.Duration(config.CF.TaskTimeout)): | ||||
| 			log.Logger.Errorw("任务超时") | ||||
| 			return false | ||||
| 		} | ||||
| 	}, | ||||
|  | ||||
| 	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", proc.Name) | ||||
| 		go proc.Kill() | ||||
| 		return true | ||||
| 	}, | ||||
|  | ||||
| 	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", proc.Name) | ||||
| 		return proc.Kill() == nil | ||||
| 	}, | ||||
| } | ||||
| @@ -3,17 +3,13 @@ package logic | ||||
| import ( | ||||
| 	"context" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"sync" | ||||
| 	"time" | ||||
|  | ||||
| 	"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" | ||||
| 	"github.com/lzh-1625/go_process_manager/utils" | ||||
|  | ||||
| 	"github.com/robfig/cron/v3" | ||||
| ) | ||||
|  | ||||
| type taskLogic struct { | ||||
| @@ -22,53 +18,25 @@ type taskLogic struct { | ||||
|  | ||||
| var TaskLogic = new(taskLogic) | ||||
|  | ||||
| func (t *taskLogic) getTaskJob(id int) (*model.TaskJob, error) { | ||||
| func (t *taskLogic) getTaskJob(id int) (*TaskJob, error) { | ||||
| 	c, ok := t.taskJobMap.Load(id) | ||||
| 	if !ok { | ||||
| 		return nil, errors.New("don't exist this task id") | ||||
| 	} | ||||
| 	return c.(*model.TaskJob), nil | ||||
| 	return c.(*TaskJob), nil | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) InitTaskJob() { | ||||
| 	for _, v := range repository.TaskRepository.GetAllTask() { | ||||
| 		tj := &model.TaskJob{ | ||||
| 			Task:      &v, | ||||
| 			StartTime: time.Now(), | ||||
| 		} | ||||
| 		if tj.Task.Cron != "" { | ||||
| 			c := cron.New() | ||||
| 			_, err := c.AddFunc(v.Cron, t.cronHandle(tj)) | ||||
| 			if err != nil { | ||||
| 				log.Logger.Errorw("定时任务创建失败", "err", err, "id", v.Id) | ||||
| 				continue | ||||
| 			} | ||||
| 			if v.Enable { | ||||
| 				c.Start() | ||||
| 			} | ||||
| 			tj.Cron = c | ||||
| 		tj, err := NewTaskJob(v) | ||||
| 		if err != nil { | ||||
| 			log.Logger.Warnw("任务初始化失败", "err", err) | ||||
| 			continue | ||||
| 		} | ||||
| 		t.taskJobMap.Store(v.Id, tj) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) cronHandle(data *model.TaskJob) func() { | ||||
| 	return func() { | ||||
| 		log.Logger.AddAdditionalInfo("id", data.Task.Id) | ||||
| 		defer log.Logger.DeleteAdditionalInfo(1) | ||||
| 		log.Logger.Infow("定时任务启动") | ||||
| 		if data.Running { | ||||
| 			log.Logger.Infow("任务已在运行,跳过当前任务") | ||||
| 			return | ||||
| 		} | ||||
| 		ctx, cancel := context.WithCancel(context.Background()) | ||||
| 		defer cancel() | ||||
| 		data.Cancel = cancel | ||||
| 		t.run(ctx, data) | ||||
| 		log.Logger.Infow("定时任务结束") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) StopTaskJob(id int) error { | ||||
| 	taskJob, err := t.getTaskJob(id) | ||||
| 	if err != nil { | ||||
| @@ -96,9 +64,9 @@ func (t *taskLogic) GetAllTaskJob() []model.TaskVo { | ||||
| 		if err != nil { | ||||
| 			continue | ||||
| 		} | ||||
| 		result[i].Id = task.Task.Id | ||||
| 		result[i].Id = task.TaskConfig.Id | ||||
| 		result[i].Running = task.Running | ||||
| 		result[i].Enable = task.Task.Enable | ||||
| 		result[i].Enable = task.TaskConfig.Enable | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
| @@ -115,37 +83,27 @@ func (t *taskLogic) DeleteTask(id int) (err error) { | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) CreateTask(data model.Task) error { | ||||
| 	tj := &model.TaskJob{ | ||||
| 		Task:      &data, | ||||
| 		StartTime: time.Now(), | ||||
| 	} | ||||
| 	if data.Cron != "" { | ||||
| 		if _, err := cron.ParseStandard(data.Cron); err != nil { // cron表达式校验 | ||||
| 			log.Logger.Errorw("cron解析失败", "cron", data.Cron, "err", err) | ||||
| 			return err | ||||
| 		} else { | ||||
| 			c := cron.New() | ||||
| 			c.AddFunc(data.Cron, t.cronHandle(tj)) | ||||
| 			tj.Cron = c | ||||
| 		} | ||||
| 	tj, err := NewTaskJob(data) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	taskId, err := repository.TaskRepository.AddTask(data) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	data.Id = taskId | ||||
| 	t.taskJobMap.Store(data.Id, tj) | ||||
| 	tj.TaskConfig.Id = taskId | ||||
| 	t.taskJobMap.Store(taskId, tj) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) EditTask(data model.Task) error { | ||||
| 	tj, err := t.getTaskJob(data.Id) | ||||
| 	if err != nil { | ||||
| 		return fmt.Errorf("task with id %v does not exist", data.Id) | ||||
| 		return errors.New("task id not exist") | ||||
| 	} | ||||
|  | ||||
| 	if tj.Running { | ||||
| 		return errors.New("can't edit task while it is running") | ||||
| 		return errors.New("can't edit running task") | ||||
| 	} | ||||
|  | ||||
| 	if tj.Cron != nil { | ||||
| @@ -153,37 +111,9 @@ func (t *taskLogic) EditTask(data model.Task) error { | ||||
| 		tj.Cron = nil | ||||
| 	} | ||||
|  | ||||
| 	// 更新任务 | ||||
| 	tj.Task = &data | ||||
| 	tj.TaskConfig = &data | ||||
| 	tj.TaskConfig.Enable = false | ||||
|  | ||||
| 	// 如果 Cron 字段为空,直接禁用任务并返回 | ||||
| 	if tj.Task.Cron == "" { | ||||
| 		tj.Task.Enable = false | ||||
| 		return repository.TaskRepository.EditTask(data) | ||||
| 	} | ||||
|  | ||||
| 	// 校验 Cron 表达式 | ||||
| 	if _, err := cron.ParseStandard(tj.Task.Cron); err != nil { | ||||
| 		tj.Task.Enable = false | ||||
| 		return fmt.Errorf("invalid cron expression: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	// 创建 Cron 调度器 | ||||
| 	c := cron.New() | ||||
| 	_, err = c.AddFunc(data.Cron, t.cronHandle(tj)) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Errorw("failed to create cron job", "err", err, "id", data.Id) | ||||
| 		tj.Task.Enable = false | ||||
| 		return fmt.Errorf("failed to create cron job: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	// 启动 Cron 调度器 | ||||
| 	if data.Enable { | ||||
| 		c.Start() | ||||
| 	} | ||||
| 	tj.Cron = c | ||||
|  | ||||
| 	// 更新任务到数据库 | ||||
| 	return repository.TaskRepository.EditTask(data) | ||||
| } | ||||
|  | ||||
| @@ -192,16 +122,12 @@ func (t *taskLogic) EditTaskEnable(id int, status bool) error { | ||||
| 	if err != nil { | ||||
| 		return errors.New("don't exist this task id") | ||||
| 	} | ||||
| 	if tj.Cron != nil { | ||||
| 		if status { | ||||
| 			tj.Cron.Start() | ||||
| 		} else { | ||||
| 			tj.Cron.Stop() | ||||
| 		} | ||||
| 	} else if status { | ||||
| 		return errors.New("cron job create failed") | ||||
| 	if tj.TaskConfig.CronExpression == "" { | ||||
| 		return errors.New("task cron expression is empty") | ||||
| 	} | ||||
| 	if err := tj.EditStatus(status); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	tj.Task.Enable = status | ||||
| 	if err := repository.TaskRepository.EditTaskEnable(id, status); err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| @@ -228,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 | ||||
| @@ -239,3 +165,18 @@ func (t *taskLogic) RunTaskByTriggerEvent(processName string, event constants.Pr | ||||
| 		t.RunTaskById(v.Id) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t *taskLogic) RunTaskById(id int) error { | ||||
| 	task, err := t.getTaskJob(id) | ||||
| 	if err != nil { | ||||
| 		return errors.New("id不存在") | ||||
| 	} | ||||
| 	if task.Running { | ||||
| 		return errors.New("task is running") | ||||
| 	} | ||||
| 	ctx, cancel := context.WithCancel(context.Background()) | ||||
| 	defer cancel() | ||||
| 	task.Cancel = cancel | ||||
| 	task.Run(ctx) | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
							
								
								
									
										18
									
								
								internal/app/logic/ws_share.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								internal/app/logic/ws_share.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/repository" | ||||
| ) | ||||
|  | ||||
| type wsShareLogic struct{} | ||||
|  | ||||
| var WsSahreLogic = &wsShareLogic{} | ||||
|  | ||||
| func (w *wsShareLogic) GetWsShareList() []*model.WsShare { | ||||
| 	return repository.WsShare.GetWsShareList() | ||||
| } | ||||
|  | ||||
| func (w *wsShareLogic) DeleteById(id int) error { | ||||
| 	return repository.WsShare.Delete(id) | ||||
| } | ||||
							
								
								
									
										41
									
								
								internal/app/middle/logger.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								internal/app/middle/logger.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| package middle | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/eum" | ||||
| 	"github.com/lzh-1625/go_process_manager/log" | ||||
| ) | ||||
|  | ||||
| func Logger() gin.HandlerFunc { | ||||
| 	return func(ctx *gin.Context) { | ||||
| 		start := time.Now() | ||||
| 		path := ctx.Request.URL.Path | ||||
|  | ||||
| 		if !strings.HasPrefix(path, "/api") { | ||||
| 			return | ||||
| 		} | ||||
| 		// Process request | ||||
| 		ctx.Next() | ||||
| 		logKv := []any{} | ||||
| 		logKv = append(logKv, "Method", ctx.Request.Method) | ||||
| 		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(eum.CtxUserName); ok { | ||||
| 			logKv = append(logKv, "user", user) | ||||
| 		} | ||||
| 		switch { | ||||
| 		case ctx.Writer.Status() >= 200 && ctx.Writer.Status() < 300: | ||||
| 			log.Logger.Infow("\033[102mGIN\033[0m", logKv...) | ||||
| 		case ctx.Writer.Status() >= 500: | ||||
| 			log.Logger.Infow("\033[101mGIN\033[0m", logKv...) | ||||
| 		default: | ||||
| 			log.Logger.Infow("\033[103mGIN\033[0m", logKv...) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @@ -1,26 +0,0 @@ | ||||
| package middle | ||||
|  | ||||
| import ( | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/constants" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
|  | ||||
| func PanicMiddle() gin.HandlerFunc { | ||||
| 	return func(c *gin.Context) { | ||||
| 		defer func() { | ||||
| 			if err := recover(); err == 0 { | ||||
| 				if err, ok := c.Get(constants.CTXFLG_ERR); ok { | ||||
| 					rErr(c, -1, err.(string), nil) | ||||
| 				} else { | ||||
| 					rErr(c, -1, "Internal error!", nil) | ||||
| 				} | ||||
| 			} else { | ||||
| 				if err != nil { | ||||
| 					panic(err) | ||||
| 				} | ||||
| 			} | ||||
| 		}() | ||||
| 		c.Next() | ||||
| 	} | ||||
| } | ||||
| @@ -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" | ||||
| @@ -40,6 +40,7 @@ func CheckToken() gin.HandlerFunc { | ||||
| 			"/api/user/login", | ||||
| 			"/api/user/register/admin", | ||||
| 			"/api/task/api-key/", | ||||
| 			"/api/ws/share", | ||||
| 		} | ||||
| 		if !slices.ContainsFunc(whiteList, func(s string) bool { | ||||
| 			return strings.HasPrefix(c.Request.URL.Path, s) | ||||
| @@ -50,15 +51,15 @@ func CheckToken() gin.HandlerFunc { | ||||
| 			} else { | ||||
| 				token = c.Query("token") | ||||
| 			} | ||||
| 			if _, err := utils.ParseToken(token); err != nil { | ||||
| 			if _, err := utils.VerifyToken(token); err != nil { | ||||
| 				rErr(c, -2, "token校验失败", err) | ||||
| 				return | ||||
| 			} | ||||
| 			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() | ||||
| @@ -72,8 +73,8 @@ func getUser(ctx *gin.Context) (string, error) { | ||||
| 	} else { | ||||
| 		token = ctx.Query("token") | ||||
| 	} | ||||
| 	if mc, err := utils.ParseToken(token); err == nil && mc != nil { | ||||
| 		return mc.UserName, nil | ||||
| 	if mc, err := utils.VerifyToken(token); err == nil && mc != nil { | ||||
| 		return mc.Username, nil | ||||
| 	} else { | ||||
| 		return "", errors.Join(errors.New("用户信息获取失败"), err) | ||||
| 	} | ||||
|   | ||||
| @@ -17,26 +17,23 @@ type waitCond struct { | ||||
| } | ||||
|  | ||||
| var ( | ||||
| 	ProcessWaitCond = newWaitCond() | ||||
| 	TaskWaitCond    = newWaitCond() | ||||
| 	ProcessWaitCond *waitCond | ||||
| 	TaskWaitCond    *waitCond | ||||
| ) | ||||
|  | ||||
| var waitCondList []*waitCond | ||||
|  | ||||
| func InitCondTiming() { | ||||
| 	for _, v := range waitCondList { | ||||
| 		go v.timing() | ||||
| 	} | ||||
| func InitWaitCond() { | ||||
| 	ProcessWaitCond = newWaitCond() | ||||
| 	TaskWaitCond = newWaitCond() | ||||
| } | ||||
|  | ||||
| func newWaitCond() *waitCond { | ||||
| 	wc := &waitCond{ | ||||
| 		cond:    *sync.NewCond(&sync.Mutex{}), | ||||
| 		ts:      time.Now().UnixMicro(), | ||||
| 		ts:      time.Now().UnixNano(), | ||||
| 		timeMap: sync.Map{}, | ||||
| 		trigger: make(chan struct{}), | ||||
| 	} | ||||
| 	waitCondList = append(waitCondList, wc) | ||||
| 	go wc.timing() | ||||
| 	return wc | ||||
| } | ||||
|  | ||||
| @@ -70,8 +67,8 @@ func (p *waitCond) timing() { // 添加定时信号清理阻塞协程 | ||||
| 		select { | ||||
| 		case <-ticker.C: | ||||
| 		case <-p.trigger: | ||||
| 			ticker.Reset(time.Second * time.Duration(config.CF.CondWaitTime)) | ||||
| 		} | ||||
| 		ticker.Reset(time.Second * time.Duration(config.CF.CondWaitTime)) | ||||
| 		p.cond.Broadcast() | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -83,16 +83,16 @@ type EsResp struct { | ||||
| } | ||||
|  | ||||
| type LogResp struct { | ||||
| 	Total int64        `json:"total"` | ||||
| 	Data  []ProcessLog `json:"data"` | ||||
| 	Total int64         `json:"total"` | ||||
| 	Data  []*ProcessLog `json:"data"` | ||||
| } | ||||
|  | ||||
| type ProcessLog struct { | ||||
| 	Id    int    `json:"id,omitempty" gorm:"primaryKey;autoIncrement;column:id" ` | ||||
| 	Log   string `json:"log" gorm:"column:log" type:"text"` | ||||
| 	Time  int64  `json:"time" gorm:"column:time" type:"long"` | ||||
| 	Name  string `json:"name" gorm:"column:name" type:"text"` | ||||
| 	Using string `json:"using" gorm:"column:using" type:"keyword"` | ||||
| 	Log   string `json:"log" gorm:"column:log"` | ||||
| 	Time  int64  `json:"time" gorm:"column:time"` | ||||
| 	Name  string `json:"name" gorm:"column:name"` | ||||
| 	Using string `json:"using" gorm:"column:using"` | ||||
| } | ||||
|  | ||||
| func (n *ProcessLog) TableName() string { | ||||
|   | ||||
							
								
								
									
										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" | ||||
| } | ||||
| @@ -4,3 +4,11 @@ type FileStruct struct { | ||||
| 	Name  string `json:"name"` | ||||
| 	IsDir bool   `json:"isDir"` | ||||
| } | ||||
|  | ||||
| type FilePathHandlerReq struct { | ||||
| 	Path string `form:"path" binding:"required"` | ||||
| } | ||||
|  | ||||
| type FileReadHandlerReq struct { | ||||
| 	FilePath string `form:"filePath" binding:"required"` | ||||
| } | ||||
|   | ||||
| @@ -1,29 +1,29 @@ | ||||
| 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 { | ||||
| 	CpuCapacity float64   `json:"cpuCapacity"` | ||||
| 	MemCapacity float64   `json:"memCapacity"` | ||||
| 	CpuCapacity float64   `json:"cpuCapacity,omitempty"` | ||||
| 	MemCapacity float64   `json:"memCapacity,omitempty"` | ||||
| 	Cpu         []float64 `json:"cpu"` | ||||
| 	Mem         []float64 `json:"mem"` | ||||
| 	Time        []string  `json:"time"` | ||||
| } | ||||
|  | ||||
| type State struct { | ||||
| 	State constants.ProcessState `json:"state"` | ||||
| 	Info  string                 `json:"info"` | ||||
| 	State eum.ProcessState `json:"state"` | ||||
| 	Info  string           `json:"info"` | ||||
| } | ||||
|   | ||||
| @@ -1,22 +1,28 @@ | ||||
| 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" json:"name"` | ||||
| 	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 { | ||||
| 	return "process" | ||||
| } | ||||
|  | ||||
| type ProcessShare struct { | ||||
| 	Minutes int  `json:"minutes"` | ||||
| 	Pid     int  `json:"pid"` | ||||
| 	Write   bool `json:"write"` | ||||
| } | ||||
|   | ||||
| @@ -1,42 +1,31 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/constants" | ||||
|  | ||||
| 	"github.com/robfig/cron/v3" | ||||
| 	"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" ` | ||||
| 	Cron            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 { | ||||
| 	return "task" | ||||
| } | ||||
|  | ||||
| type TaskJob struct { | ||||
| 	Cron      *cron.Cron         `json:"-"` | ||||
| 	Task      *Task              `json:"task"` | ||||
| 	Running   bool               `json:"running"` | ||||
| 	Cancel    context.CancelFunc `json:"-"` | ||||
| 	StartTime time.Time          `json:"startTime"` | ||||
| 	EndTime   time.Time          `json:"endTime"` | ||||
| } | ||||
|  | ||||
| type TaskVo struct { | ||||
| 	Task | ||||
| 	ProcessName string    `gorm:"column:process_name;" json:"processName"` | ||||
|   | ||||
| @@ -3,17 +3,26 @@ 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 { | ||||
| 	return "users" | ||||
| } | ||||
|  | ||||
| type LoginHandlerReq struct { | ||||
| 	Account  string `form:"account" binding:"required"` | ||||
| 	Password string `form:"password" binding:"required"` | ||||
| } | ||||
|  | ||||
| type DeleteUserReq struct { | ||||
| 	Account string `form:"account" binding:"required"` | ||||
| } | ||||
|   | ||||
							
								
								
									
										27
									
								
								internal/app/model/ws.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								internal/app/model/ws.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| package model | ||||
|  | ||||
| import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"gorm.io/gorm" | ||||
| ) | ||||
|  | ||||
| type WsShare struct { | ||||
| 	gorm.Model | ||||
| 	Pid        int       `gorm:"column:pid" json:"pid"` | ||||
| 	Write      bool      `gorm:"column:write" json:"write"` | ||||
| 	ExpireTime time.Time `gorm:"column:expire_time" json:"expireTime"` | ||||
| 	CreateBy   string    `gorm:"column:create_by" json:"createBy"` | ||||
| 	Token      string    `gorm:"column:token" json:"token"` | ||||
| } | ||||
|  | ||||
| func (WsShare) TableName() string { | ||||
| 	return "ws_share" | ||||
| } | ||||
|  | ||||
| type WebsocketHandleReq struct { | ||||
| 	Uuid  int    `form:"uuid"` | ||||
| 	Cols  int    `form:"cols"` | ||||
| 	Rows  int    `form:"rows"` | ||||
| 	Token string `form:"token"` | ||||
| } | ||||
| @@ -1,7 +1,10 @@ | ||||
| package repository | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/repository/query" | ||||
| ) | ||||
|  | ||||
| type configRepository struct{} | ||||
| @@ -9,11 +12,11 @@ type configRepository struct{} | ||||
| var ConfigRepository = new(configRepository) | ||||
|  | ||||
| func (c *configRepository) GetConfigValue(key string) (string, error) { | ||||
| 	var result string | ||||
| 	if err := db.Model(&model.Config{}).Select("value").Where(&model.Config{Key: key}).First(&result).Error; err != nil { | ||||
| 		return "", err | ||||
| 	data, err := query.Config.Select(query.Config.Value).Where(query.Config.Key.Eq(key)).First() | ||||
| 	if data == nil || err != nil { | ||||
| 		return "", errors.ErrUnsupported | ||||
| 	} | ||||
| 	return result, nil | ||||
| 	return *data.Value, err | ||||
| } | ||||
|  | ||||
| func (c *configRepository) SetConfigValue(key, value string) error { | ||||
|   | ||||
| @@ -6,6 +6,7 @@ import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/repository/query" | ||||
|  | ||||
| 	"github.com/glebarez/sqlite" | ||||
| 	"gorm.io/gorm" | ||||
| @@ -40,6 +41,18 @@ func InitDb() { | ||||
| 	} | ||||
| 	sqlDB.SetConnMaxLifetime(time.Hour) | ||||
| 	db = gdb.Session(&defaultConfig) | ||||
| 	// db = gdb.Session(&defaultConfig).Debug() | ||||
| 	db.AutoMigrate(&model.Process{}, &model.User{}, &model.Permission{}, &model.Push{}, &model.Config{}, &model.ProcessLog{}, &model.Task{}) | ||||
| 	// db = db.Debug() | ||||
| 	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) { | ||||
|  | ||||
| } | ||||
| @@ -1,7 +1,11 @@ | ||||
| package repository | ||||
|  | ||||
| import ( | ||||
| 	"context" | ||||
|  | ||||
| 	"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/search" | ||||
| 	"github.com/lzh-1625/go_process_manager/log" | ||||
| ) | ||||
|  | ||||
| @@ -15,29 +19,36 @@ func (l *logRepository) InsertLog(data model.ProcessLog) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (l *logRepository) SearchLog(query model.GetLogReq) (result []model.ProcessLog, total int64) { | ||||
| 	tx := db.Model(&model.ProcessLog{}).Where(&model.ProcessLog{ | ||||
| 		Name:  query.Match.Name, | ||||
| 		Using: query.Match.Using, | ||||
| 	}) | ||||
| 	if query.Match.Log != "" { | ||||
| 		tx.Where("log like ?", "%"+query.Match.Log+"%") | ||||
| func (l *logRepository) SearchLog(req model.GetLogReq, logQuery []search.Query) (result []*model.ProcessLog, total int64) { | ||||
| 	q := query.ProcessLog.WithContext(context.TODO()) | ||||
| 	if req.Match.Name != "" { | ||||
| 		q = q.Where(query.ProcessLog.Name.Eq(req.Match.Name)) | ||||
| 	} | ||||
| 	if query.Sort == "desc" { | ||||
| 		tx.Order("time desc") | ||||
| 	if req.Match.Using != "" { | ||||
| 		q = q.Where(query.ProcessLog.Using.Eq(req.Match.Using)) | ||||
| 	} | ||||
| 	if query.TimeRange.StartTime != 0 { | ||||
| 		tx.Where("time > ?", query.TimeRange.StartTime) | ||||
|  | ||||
| 	for _, v := range logQuery { | ||||
| 		switch v.Cond { | ||||
| 		case search.Match, search.WildCard: | ||||
| 			q = q.Where(query.ProcessLog.Log.Like("%" + v.Content + "%")) | ||||
| 		case search.NotMatch, search.NotWildCard: | ||||
| 			q = q.Where(query.ProcessLog.Log.NotLike("%" + v.Content + "%")) | ||||
| 		} | ||||
| 	} | ||||
| 	if query.TimeRange.EndTime != 0 { | ||||
| 		tx.Where("time < ?", query.TimeRange.EndTime) | ||||
|  | ||||
| 	if req.Sort == "desc" { | ||||
| 		q = q.Order(query.ProcessLog.Time.Desc()) | ||||
| 	} | ||||
| 	if len(query.FilterName) != 0 { | ||||
| 		tx.Where("name in ?", query.FilterName) | ||||
| 	if req.TimeRange.StartTime != 0 { | ||||
| 		q = q.Where(query.ProcessLog.Time.Gte(req.TimeRange.StartTime)) | ||||
| 	} | ||||
| 	tx.Count(&total) | ||||
| 	tx.Limit(query.Page.Size) | ||||
| 	tx.Offset(query.Page.From) | ||||
| 	tx.Find(&result) | ||||
| 	if req.TimeRange.EndTime != 0 { | ||||
| 		q = q.Where(query.ProcessLog.Time.Lte(req.TimeRange.EndTime)) | ||||
| 	} | ||||
| 	if len(req.FilterName) != 0 { | ||||
| 		q = q.Where(query.ProcessLog.Name.In(req.FilterName...)) | ||||
| 	} | ||||
| 	result, total, _ = q.FindByPage(req.Page.From, req.Page.Size) | ||||
| 	return | ||||
| } | ||||
|   | ||||
| @@ -1,12 +1,12 @@ | ||||
| package repository | ||||
|  | ||||
| import ( | ||||
| 	"reflect" | ||||
| 	"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" | ||||
|  | ||||
| 	"gorm.io/gorm" | ||||
| ) | ||||
|  | ||||
| @@ -16,9 +16,24 @@ var PermissionRepository = new(permissionRepository) | ||||
|  | ||||
| func (p *permissionRepository) GetPermssionList(account string) []model.PermissionPo { | ||||
| 	result := []model.PermissionPo{} | ||||
| 	if err := db.Raw(`SELECT p.name ,p.uuid as pid,p2.owned ,p2."start" ,p2.stop ,p2.terminal,p2.log ,p2.write     | ||||
| 	FROM users u full join process p left join permission p2 on p2.account == u.account and p2.pid =p.uuid  | ||||
| 	WHERE u.account = ? or u.account ISNULL`, account).Find(&result); err.Error != nil { | ||||
| 	if err := db.Raw(`SELECT | ||||
| 	p.name , | ||||
| 	p.uuid as pid, | ||||
| 	p2.owned , | ||||
| 	p2."start" , | ||||
| 	p2.stop , | ||||
| 	p2.terminal, | ||||
| 	p2.log , | ||||
| 	p2.write | ||||
| FROM | ||||
| 	users u | ||||
| full join process p | ||||
| left join permission p2 on | ||||
| 	p2.account == u.account | ||||
| 	and p2.pid = p.uuid | ||||
| WHERE | ||||
| 	u.account = ? | ||||
| 	or u.account ISNULL`, account).Find(&result); err.Error != nil { | ||||
| 		log.Logger.Warnw("权限查询失败", "err", err) | ||||
| 	} | ||||
|  | ||||
| @@ -26,20 +41,22 @@ func (p *permissionRepository) GetPermssionList(account string) []model.Permissi | ||||
| } | ||||
|  | ||||
| func (p *permissionRepository) EditPermssion(data model.Permission) error { | ||||
| 	if db.Model(&model.Permission{}).Where(&model.Permission{Account: data.Account, Pid: data.Pid}).First(nil).Error == gorm.ErrRecordNotFound { | ||||
| 		db.Omit("name").Create(&model.Permission{ | ||||
| 	per := query.Permission | ||||
| 	if _, err := per.Where(per.Account.Eq(data.Account)).Where(per.Pid.Eq(data.Pid)).First(); errors.Is(err, gorm.ErrRecordNotFound) { | ||||
| 		per.Create(&model.Permission{ | ||||
| 			Account: data.Account, | ||||
| 			Pid:     data.Pid, | ||||
| 		}) | ||||
| 	} | ||||
| 	return db.Model(&model.Permission{}).Where(&model.Permission{Account: data.Account, Pid: data.Pid}).Updates(map[string]interface{}{ | ||||
| 		"owned":    data.Owned, | ||||
| 		"start":    data.Start, | ||||
| 		"stop":     data.Stop, | ||||
| 		"terminal": data.Terminal, | ||||
| 		"log":      data.Log, | ||||
| 		"write":    data.Write, | ||||
| 	}).Error | ||||
| 	_, err := per.Where(per.Account.Eq(data.Account)).Where(per.Pid.Eq(data.Pid)).Updates(map[string]any{ | ||||
| 		per.Owned.ColumnName().String():    data.Owned, | ||||
| 		per.Start.ColumnName().String():    data.Start, | ||||
| 		per.Stop.ColumnName().String():     data.Stop, | ||||
| 		per.Terminal.ColumnName().String(): data.Terminal, | ||||
| 		per.Log.ColumnName().String():      data.Log, | ||||
| 		per.Write.ColumnName().String():    data.Write, | ||||
| 	}) | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *permissionRepository) GetPermission(user string, pid int) (result model.Permission) { | ||||
| @@ -47,9 +64,20 @@ func (p *permissionRepository) GetPermission(user string, pid int) (result model | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *permissionRepository) GetProcessNameByPermission(user string, op constants.OprPermission) (result []string) { | ||||
| 	query := model.PermissionPo{Account: user, Owned: true} | ||||
| 	reflect.ValueOf(&query).Elem().FieldByName(string(op)).SetBool(true) | ||||
| 	db.Model(&model.Permission{}).Select("name").Joins("right join process p on p.uuid = pid").Where(query).Find(&result) | ||||
| 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 eum.OperationLog: | ||||
| 		tx = tx.Where(query.Permission.Log.Is(true)) | ||||
| 	case eum.OperationStart: | ||||
| 		tx = tx.Where(query.Permission.Start.Is(true)) | ||||
| 	case eum.OperationStop: | ||||
| 		tx = tx.Where(query.Permission.Stop.Is(true)) | ||||
| 	case eum.OperationTerminal: | ||||
| 		tx = tx.Where(query.Permission.Terminal.Is(true)) | ||||
| 	case eum.OperationTerminalWrite: | ||||
| 		tx = tx.Where(query.Permission.Write.Is(true)) | ||||
| 	} | ||||
| 	tx.Scan(&result) | ||||
| 	return | ||||
| } | ||||
|   | ||||
| @@ -1,12 +1,9 @@ | ||||
| package repository | ||||
|  | ||||
| import ( | ||||
| 	"errors" | ||||
|  | ||||
| 	"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" | ||||
|  | ||||
| 	"gorm.io/gorm" | ||||
| ) | ||||
|  | ||||
| type processRepository struct{} | ||||
| @@ -15,7 +12,6 @@ var ProcessRepository = new(processRepository) | ||||
|  | ||||
| func (p *processRepository) GetAllProcessConfig() []model.Process { | ||||
| 	result := []model.Process{} | ||||
|  | ||||
| 	tx := db.Find(&result) | ||||
| 	if tx.Error != nil { | ||||
| 		log.Logger.Error(tx.Error) | ||||
| @@ -26,40 +22,25 @@ func (p *processRepository) GetAllProcessConfig() []model.Process { | ||||
|  | ||||
| func (p *processRepository) GetProcessConfigByUser(username string) []model.Process { | ||||
| 	result := []model.Process{} | ||||
| 	tx := db.Raw(`SELECT p.* FROM permission left join process p where pid =p.uuid and owned  = 1 and account = ?`, username).Scan(&result) | ||||
| 	if tx.Error != nil { | ||||
| 		log.Logger.Error(tx.Error) | ||||
| 	err := query.Process.LeftJoin(query.Permission, query.Process.Uuid.EqCol(query.Permission.Pid)). | ||||
| 		Where(query.Permission.Owned.Is(true)). | ||||
| 		Where(query.Permission.Account.Eq(username)). | ||||
| 		Scan(&result) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Error(err) | ||||
| 		return []model.Process{} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
|  | ||||
| func (p *processRepository) UpdateProcessConfig(process model.Process) error { | ||||
| 	tx := db.Save(&process) | ||||
| 	return tx.Error | ||||
| 	return db.Save(&process).Error | ||||
| } | ||||
|  | ||||
| func (p *processRepository) AddProcessConfig(process model.Process) (int, error) { | ||||
| 	var existingProcess model.Process | ||||
| 	err := db.Model(&model.Process{}).Where("name = ?", process.Name).First(&existingProcess).Error | ||||
|  | ||||
| 	if err != nil && err != gorm.ErrRecordNotFound { | ||||
| 		log.Logger.Error(err) | ||||
| 		return 0, err | ||||
| 	} | ||||
|  | ||||
| 	if err == nil { | ||||
|  | ||||
| 		return 0, errors.New("process name already exists") | ||||
| 	} | ||||
|  | ||||
| 	tx := db.Create(&process) | ||||
| 	if tx.Error != nil { | ||||
| 		log.Logger.Error(tx.Error) | ||||
| 		return 0, tx.Error | ||||
| 	} | ||||
|  | ||||
| 	return process.Uuid, nil | ||||
| func (p *processRepository) AddProcessConfig(process model.Process) (id int, err error) { | ||||
| 	err = db.Create(&process).Error | ||||
| 	id = process.Uuid | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *processRepository) DeleteProcessConfig(uuid int) error { | ||||
| @@ -68,12 +49,7 @@ func (p *processRepository) DeleteProcessConfig(uuid int) error { | ||||
| 	}).Error | ||||
| } | ||||
|  | ||||
| func (p *processRepository) GetProcessConfigById(uuid int) model.Process { | ||||
| 	result := model.Process{} | ||||
| 	tx := db.Model(&model.Process{}).Where(&model.Process{Uuid: uuid}).First(&result) | ||||
| 	if tx.Error != nil { | ||||
| 		log.Logger.Error(tx.Error) | ||||
| 		return model.Process{} | ||||
| 	} | ||||
| 	return result | ||||
| func (p *processRepository) GetProcessConfigById(uuid int) (data model.Process, err error) { | ||||
| 	err = db.Model(&model.Process{}).Where(&model.Process{Uuid: uuid}).First(&data).Error | ||||
| 	return | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ 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 pushRepository struct{} | ||||
| @@ -32,7 +33,7 @@ func (p *pushRepository) DeletePushConfig(id int) error { | ||||
| 	}).Error | ||||
| } | ||||
|  | ||||
| func (p *pushRepository) GetPushConfigByIds(ids []int) (result []model.Push) { | ||||
| 	db.Model(&model.Push{}).Where("id in ?", ids).Find(&result) | ||||
| func (p *pushRepository) GetPushConfigByIds(ids []int64) (result []*model.Push) { | ||||
| 	result, _ = query.Push.Where(query.Push.Id.In(ids...)).Find() | ||||
| 	return | ||||
| } | ||||
|   | ||||
							
								
								
									
										390
									
								
								internal/app/repository/query/config.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										390
									
								
								internal/app/repository/query/config.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,390 @@ | ||||
| // 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 newConfig(db *gorm.DB, opts ...gen.DOOption) config { | ||||
| 	_config := config{} | ||||
|  | ||||
| 	_config.configDo.UseDB(db, opts...) | ||||
| 	_config.configDo.UseModel(&model.Config{}) | ||||
|  | ||||
| 	tableName := _config.configDo.TableName() | ||||
| 	_config.ALL = field.NewAsterisk(tableName) | ||||
| 	_config.Id = field.NewInt(tableName, "id") | ||||
| 	_config.Key = field.NewString(tableName, "key") | ||||
| 	_config.Value = field.NewString(tableName, "value") | ||||
|  | ||||
| 	_config.fillFieldMap() | ||||
|  | ||||
| 	return _config | ||||
| } | ||||
|  | ||||
| type config struct { | ||||
| 	configDo | ||||
|  | ||||
| 	ALL   field.Asterisk | ||||
| 	Id    field.Int | ||||
| 	Key   field.String | ||||
| 	Value field.String | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (c config) Table(newTableName string) *config { | ||||
| 	c.configDo.UseTable(newTableName) | ||||
| 	return c.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (c config) As(alias string) *config { | ||||
| 	c.configDo.DO = *(c.configDo.As(alias).(*gen.DO)) | ||||
| 	return c.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (c *config) updateTableName(table string) *config { | ||||
| 	c.ALL = field.NewAsterisk(table) | ||||
| 	c.Id = field.NewInt(table, "id") | ||||
| 	c.Key = field.NewString(table, "key") | ||||
| 	c.Value = field.NewString(table, "value") | ||||
|  | ||||
| 	c.fillFieldMap() | ||||
|  | ||||
| 	return c | ||||
| } | ||||
|  | ||||
| func (c *config) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := c.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (c *config) fillFieldMap() { | ||||
| 	c.fieldMap = make(map[string]field.Expr, 3) | ||||
| 	c.fieldMap["id"] = c.Id | ||||
| 	c.fieldMap["key"] = c.Key | ||||
| 	c.fieldMap["value"] = c.Value | ||||
| } | ||||
|  | ||||
| func (c config) clone(db *gorm.DB) config { | ||||
| 	c.configDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return c | ||||
| } | ||||
|  | ||||
| func (c config) replaceDB(db *gorm.DB) config { | ||||
| 	c.configDo.ReplaceDB(db) | ||||
| 	return c | ||||
| } | ||||
|  | ||||
| type configDo struct{ gen.DO } | ||||
|  | ||||
| type IConfigDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IConfigDo | ||||
| 	WithContext(ctx context.Context) IConfigDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IConfigDo | ||||
| 	WriteDB() IConfigDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IConfigDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IConfigDo | ||||
| 	Not(conds ...gen.Condition) IConfigDo | ||||
| 	Or(conds ...gen.Condition) IConfigDo | ||||
| 	Select(conds ...field.Expr) IConfigDo | ||||
| 	Where(conds ...gen.Condition) IConfigDo | ||||
| 	Order(conds ...field.Expr) IConfigDo | ||||
| 	Distinct(cols ...field.Expr) IConfigDo | ||||
| 	Omit(cols ...field.Expr) IConfigDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IConfigDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IConfigDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IConfigDo | ||||
| 	Group(cols ...field.Expr) IConfigDo | ||||
| 	Having(conds ...gen.Condition) IConfigDo | ||||
| 	Limit(limit int) IConfigDo | ||||
| 	Offset(offset int) IConfigDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IConfigDo | ||||
| 	Unscoped() IConfigDo | ||||
| 	Create(values ...*model.Config) error | ||||
| 	CreateInBatches(values []*model.Config, batchSize int) error | ||||
| 	Save(values ...*model.Config) error | ||||
| 	First() (*model.Config, error) | ||||
| 	Take() (*model.Config, error) | ||||
| 	Last() (*model.Config, error) | ||||
| 	Find() ([]*model.Config, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Config, err error) | ||||
| 	FindInBatches(result *[]*model.Config, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.Config) (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) IConfigDo | ||||
| 	Assign(attrs ...field.AssignExpr) IConfigDo | ||||
| 	Joins(fields ...field.RelationField) IConfigDo | ||||
| 	Preload(fields ...field.RelationField) IConfigDo | ||||
| 	FirstOrInit() (*model.Config, error) | ||||
| 	FirstOrCreate() (*model.Config, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.Config, 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) IConfigDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (c configDo) Debug() IConfigDo { | ||||
| 	return c.withDO(c.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (c configDo) WithContext(ctx context.Context) IConfigDo { | ||||
| 	return c.withDO(c.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (c configDo) ReadDB() IConfigDo { | ||||
| 	return c.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (c configDo) WriteDB() IConfigDo { | ||||
| 	return c.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (c configDo) Session(config *gorm.Session) IConfigDo { | ||||
| 	return c.withDO(c.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Clauses(conds ...clause.Expression) IConfigDo { | ||||
| 	return c.withDO(c.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Returning(value interface{}, columns ...string) IConfigDo { | ||||
| 	return c.withDO(c.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Not(conds ...gen.Condition) IConfigDo { | ||||
| 	return c.withDO(c.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Or(conds ...gen.Condition) IConfigDo { | ||||
| 	return c.withDO(c.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Select(conds ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Where(conds ...gen.Condition) IConfigDo { | ||||
| 	return c.withDO(c.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Order(conds ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Distinct(cols ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Omit(cols ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Join(table schema.Tabler, on ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) LeftJoin(table schema.Tabler, on ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) RightJoin(table schema.Tabler, on ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Group(cols ...field.Expr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Having(conds ...gen.Condition) IConfigDo { | ||||
| 	return c.withDO(c.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Limit(limit int) IConfigDo { | ||||
| 	return c.withDO(c.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Offset(offset int) IConfigDo { | ||||
| 	return c.withDO(c.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IConfigDo { | ||||
| 	return c.withDO(c.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Unscoped() IConfigDo { | ||||
| 	return c.withDO(c.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (c configDo) Create(values ...*model.Config) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return c.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (c configDo) CreateInBatches(values []*model.Config, batchSize int) error { | ||||
| 	return c.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 (c configDo) Save(values ...*model.Config) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return c.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (c configDo) First() (*model.Config, error) { | ||||
| 	if result, err := c.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Config), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c configDo) Take() (*model.Config, error) { | ||||
| 	if result, err := c.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Config), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c configDo) Last() (*model.Config, error) { | ||||
| 	if result, err := c.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Config), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c configDo) Find() ([]*model.Config, error) { | ||||
| 	result, err := c.DO.Find() | ||||
| 	return result.([]*model.Config), err | ||||
| } | ||||
|  | ||||
| func (c configDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Config, err error) { | ||||
| 	buf := make([]*model.Config, 0, batchSize) | ||||
| 	err = c.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 (c configDo) FindInBatches(result *[]*model.Config, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return c.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (c configDo) Attrs(attrs ...field.AssignExpr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Assign(attrs ...field.AssignExpr) IConfigDo { | ||||
| 	return c.withDO(c.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (c configDo) Joins(fields ...field.RelationField) IConfigDo { | ||||
| 	for _, _f := range fields { | ||||
| 		c = *c.withDO(c.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &c | ||||
| } | ||||
|  | ||||
| func (c configDo) Preload(fields ...field.RelationField) IConfigDo { | ||||
| 	for _, _f := range fields { | ||||
| 		c = *c.withDO(c.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &c | ||||
| } | ||||
|  | ||||
| func (c configDo) FirstOrInit() (*model.Config, error) { | ||||
| 	if result, err := c.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Config), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c configDo) FirstOrCreate() (*model.Config, error) { | ||||
| 	if result, err := c.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Config), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (c configDo) FindByPage(offset int, limit int) (result []*model.Config, count int64, err error) { | ||||
| 	result, err = c.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 = c.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c configDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = c.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = c.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (c configDo) Scan(result interface{}) (err error) { | ||||
| 	return c.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (c configDo) Delete(models ...*model.Config) (result gen.ResultInfo, err error) { | ||||
| 	return c.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (c *configDo) withDO(do gen.Dao) *configDo { | ||||
| 	c.DO = *do.(*gen.DO) | ||||
| 	return c | ||||
| } | ||||
							
								
								
									
										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 | ||||
| } | ||||
							
								
								
									
										167
									
								
								internal/app/repository/query/gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								internal/app/repository/query/gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| // 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" | ||||
|  | ||||
| 	"gorm.io/gorm" | ||||
|  | ||||
| 	"gorm.io/gen" | ||||
|  | ||||
| 	"gorm.io/plugin/dbresolver" | ||||
| ) | ||||
|  | ||||
| var ( | ||||
| 	Q          = new(Query) | ||||
| 	Config     *config | ||||
| 	Event      *event | ||||
| 	Permission *permission | ||||
| 	Process    *process | ||||
| 	ProcessLog *processLog | ||||
| 	Push       *push | ||||
| 	Task       *task | ||||
| 	User       *user | ||||
| 	WsShare    *wsShare | ||||
| ) | ||||
|  | ||||
| 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 | ||||
| 	Push = &Q.Push | ||||
| 	Task = &Q.Task | ||||
| 	User = &Q.User | ||||
| 	WsShare = &Q.WsShare | ||||
| } | ||||
|  | ||||
| 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...), | ||||
| 		Push:       newPush(db, opts...), | ||||
| 		Task:       newTask(db, opts...), | ||||
| 		User:       newUser(db, opts...), | ||||
| 		WsShare:    newWsShare(db, opts...), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type Query struct { | ||||
| 	db *gorm.DB | ||||
|  | ||||
| 	Config     config | ||||
| 	Event      event | ||||
| 	Permission permission | ||||
| 	Process    process | ||||
| 	ProcessLog processLog | ||||
| 	Push       push | ||||
| 	Task       task | ||||
| 	User       user | ||||
| 	WsShare    wsShare | ||||
| } | ||||
|  | ||||
| func (q *Query) Available() bool { return q.db != nil } | ||||
|  | ||||
| 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), | ||||
| 		Push:       q.Push.clone(db), | ||||
| 		Task:       q.Task.clone(db), | ||||
| 		User:       q.User.clone(db), | ||||
| 		WsShare:    q.WsShare.clone(db), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (q *Query) ReadDB() *Query { | ||||
| 	return q.ReplaceDB(q.db.Clauses(dbresolver.Read)) | ||||
| } | ||||
|  | ||||
| func (q *Query) WriteDB() *Query { | ||||
| 	return q.ReplaceDB(q.db.Clauses(dbresolver.Write)) | ||||
| } | ||||
|  | ||||
| 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), | ||||
| 		Push:       q.Push.replaceDB(db), | ||||
| 		Task:       q.Task.replaceDB(db), | ||||
| 		User:       q.User.replaceDB(db), | ||||
| 		WsShare:    q.WsShare.replaceDB(db), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| type queryCtx struct { | ||||
| 	Config     IConfigDo | ||||
| 	Event      IEventDo | ||||
| 	Permission IPermissionDo | ||||
| 	Process    IProcessDo | ||||
| 	ProcessLog IProcessLogDo | ||||
| 	Push       IPushDo | ||||
| 	Task       ITaskDo | ||||
| 	User       IUserDo | ||||
| 	WsShare    IWsShareDo | ||||
| } | ||||
|  | ||||
| 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), | ||||
| 		Push:       q.Push.WithContext(ctx), | ||||
| 		Task:       q.Task.WithContext(ctx), | ||||
| 		User:       q.User.WithContext(ctx), | ||||
| 		WsShare:    q.WsShare.WithContext(ctx), | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (q *Query) Transaction(fc func(tx *Query) error, opts ...*sql.TxOptions) error { | ||||
| 	return q.db.Transaction(func(tx *gorm.DB) error { return fc(q.clone(tx)) }, opts...) | ||||
| } | ||||
|  | ||||
| func (q *Query) Begin(opts ...*sql.TxOptions) *QueryTx { | ||||
| 	tx := q.db.Begin(opts...) | ||||
| 	return &QueryTx{Query: q.clone(tx), Error: tx.Error} | ||||
| } | ||||
|  | ||||
| type QueryTx struct { | ||||
| 	*Query | ||||
| 	Error error | ||||
| } | ||||
|  | ||||
| func (q *QueryTx) Commit() error { | ||||
| 	return q.db.Commit().Error | ||||
| } | ||||
|  | ||||
| func (q *QueryTx) Rollback() error { | ||||
| 	return q.db.Rollback().Error | ||||
| } | ||||
|  | ||||
| func (q *QueryTx) SavePoint(name string) error { | ||||
| 	return q.db.SavePoint(name).Error | ||||
| } | ||||
|  | ||||
| func (q *QueryTx) RollbackTo(name string) error { | ||||
| 	return q.db.RollbackTo(name).Error | ||||
| } | ||||
							
								
								
									
										414
									
								
								internal/app/repository/query/permission.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										414
									
								
								internal/app/repository/query/permission.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,414 @@ | ||||
| // 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 newPermission(db *gorm.DB, opts ...gen.DOOption) permission { | ||||
| 	_permission := permission{} | ||||
|  | ||||
| 	_permission.permissionDo.UseDB(db, opts...) | ||||
| 	_permission.permissionDo.UseModel(&model.Permission{}) | ||||
|  | ||||
| 	tableName := _permission.permissionDo.TableName() | ||||
| 	_permission.ALL = field.NewAsterisk(tableName) | ||||
| 	_permission.Id = field.NewInt64(tableName, "id") | ||||
| 	_permission.Account = field.NewString(tableName, "account") | ||||
| 	_permission.Pid = field.NewInt32(tableName, "pid") | ||||
| 	_permission.Owned = field.NewBool(tableName, "owned") | ||||
| 	_permission.Start = field.NewBool(tableName, "start") | ||||
| 	_permission.Stop = field.NewBool(tableName, "stop") | ||||
| 	_permission.Terminal = field.NewBool(tableName, "terminal") | ||||
| 	_permission.Write = field.NewBool(tableName, "write") | ||||
| 	_permission.Log = field.NewBool(tableName, "log") | ||||
|  | ||||
| 	_permission.fillFieldMap() | ||||
|  | ||||
| 	return _permission | ||||
| } | ||||
|  | ||||
| type permission struct { | ||||
| 	permissionDo | ||||
|  | ||||
| 	ALL      field.Asterisk | ||||
| 	Id       field.Int64 | ||||
| 	Account  field.String | ||||
| 	Pid      field.Int32 | ||||
| 	Owned    field.Bool | ||||
| 	Start    field.Bool | ||||
| 	Stop     field.Bool | ||||
| 	Terminal field.Bool | ||||
| 	Write    field.Bool | ||||
| 	Log      field.Bool | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (p permission) Table(newTableName string) *permission { | ||||
| 	p.permissionDo.UseTable(newTableName) | ||||
| 	return p.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (p permission) As(alias string) *permission { | ||||
| 	p.permissionDo.DO = *(p.permissionDo.As(alias).(*gen.DO)) | ||||
| 	return p.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (p *permission) updateTableName(table string) *permission { | ||||
| 	p.ALL = field.NewAsterisk(table) | ||||
| 	p.Id = field.NewInt64(table, "id") | ||||
| 	p.Account = field.NewString(table, "account") | ||||
| 	p.Pid = field.NewInt32(table, "pid") | ||||
| 	p.Owned = field.NewBool(table, "owned") | ||||
| 	p.Start = field.NewBool(table, "start") | ||||
| 	p.Stop = field.NewBool(table, "stop") | ||||
| 	p.Terminal = field.NewBool(table, "terminal") | ||||
| 	p.Write = field.NewBool(table, "write") | ||||
| 	p.Log = field.NewBool(table, "log") | ||||
|  | ||||
| 	p.fillFieldMap() | ||||
|  | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p *permission) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := p.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (p *permission) fillFieldMap() { | ||||
| 	p.fieldMap = make(map[string]field.Expr, 9) | ||||
| 	p.fieldMap["id"] = p.Id | ||||
| 	p.fieldMap["account"] = p.Account | ||||
| 	p.fieldMap["pid"] = p.Pid | ||||
| 	p.fieldMap["owned"] = p.Owned | ||||
| 	p.fieldMap["start"] = p.Start | ||||
| 	p.fieldMap["stop"] = p.Stop | ||||
| 	p.fieldMap["terminal"] = p.Terminal | ||||
| 	p.fieldMap["write"] = p.Write | ||||
| 	p.fieldMap["log"] = p.Log | ||||
| } | ||||
|  | ||||
| func (p permission) clone(db *gorm.DB) permission { | ||||
| 	p.permissionDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p permission) replaceDB(db *gorm.DB) permission { | ||||
| 	p.permissionDo.ReplaceDB(db) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| type permissionDo struct{ gen.DO } | ||||
|  | ||||
| type IPermissionDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IPermissionDo | ||||
| 	WithContext(ctx context.Context) IPermissionDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IPermissionDo | ||||
| 	WriteDB() IPermissionDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IPermissionDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IPermissionDo | ||||
| 	Not(conds ...gen.Condition) IPermissionDo | ||||
| 	Or(conds ...gen.Condition) IPermissionDo | ||||
| 	Select(conds ...field.Expr) IPermissionDo | ||||
| 	Where(conds ...gen.Condition) IPermissionDo | ||||
| 	Order(conds ...field.Expr) IPermissionDo | ||||
| 	Distinct(cols ...field.Expr) IPermissionDo | ||||
| 	Omit(cols ...field.Expr) IPermissionDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IPermissionDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IPermissionDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IPermissionDo | ||||
| 	Group(cols ...field.Expr) IPermissionDo | ||||
| 	Having(conds ...gen.Condition) IPermissionDo | ||||
| 	Limit(limit int) IPermissionDo | ||||
| 	Offset(offset int) IPermissionDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IPermissionDo | ||||
| 	Unscoped() IPermissionDo | ||||
| 	Create(values ...*model.Permission) error | ||||
| 	CreateInBatches(values []*model.Permission, batchSize int) error | ||||
| 	Save(values ...*model.Permission) error | ||||
| 	First() (*model.Permission, error) | ||||
| 	Take() (*model.Permission, error) | ||||
| 	Last() (*model.Permission, error) | ||||
| 	Find() ([]*model.Permission, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Permission, err error) | ||||
| 	FindInBatches(result *[]*model.Permission, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.Permission) (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) IPermissionDo | ||||
| 	Assign(attrs ...field.AssignExpr) IPermissionDo | ||||
| 	Joins(fields ...field.RelationField) IPermissionDo | ||||
| 	Preload(fields ...field.RelationField) IPermissionDo | ||||
| 	FirstOrInit() (*model.Permission, error) | ||||
| 	FirstOrCreate() (*model.Permission, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.Permission, 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) IPermissionDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Debug() IPermissionDo { | ||||
| 	return p.withDO(p.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) WithContext(ctx context.Context) IPermissionDo { | ||||
| 	return p.withDO(p.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) ReadDB() IPermissionDo { | ||||
| 	return p.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) WriteDB() IPermissionDo { | ||||
| 	return p.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Session(config *gorm.Session) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Clauses(conds ...clause.Expression) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Returning(value interface{}, columns ...string) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Not(conds ...gen.Condition) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Or(conds ...gen.Condition) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Select(conds ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Where(conds ...gen.Condition) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Order(conds ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Distinct(cols ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Omit(cols ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Join(table schema.Tabler, on ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) RightJoin(table schema.Tabler, on ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Group(cols ...field.Expr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Having(conds ...gen.Condition) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Limit(limit int) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Offset(offset int) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Unscoped() IPermissionDo { | ||||
| 	return p.withDO(p.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Create(values ...*model.Permission) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) CreateInBatches(values []*model.Permission, batchSize int) error { | ||||
| 	return p.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 (p permissionDo) Save(values ...*model.Permission) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) First() (*model.Permission, error) { | ||||
| 	if result, err := p.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Permission), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Take() (*model.Permission, error) { | ||||
| 	if result, err := p.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Permission), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Last() (*model.Permission, error) { | ||||
| 	if result, err := p.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Permission), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Find() ([]*model.Permission, error) { | ||||
| 	result, err := p.DO.Find() | ||||
| 	return result.([]*model.Permission), err | ||||
| } | ||||
|  | ||||
| func (p permissionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Permission, err error) { | ||||
| 	buf := make([]*model.Permission, 0, batchSize) | ||||
| 	err = p.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 (p permissionDo) FindInBatches(result *[]*model.Permission, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return p.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Attrs(attrs ...field.AssignExpr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Assign(attrs ...field.AssignExpr) IPermissionDo { | ||||
| 	return p.withDO(p.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Joins(fields ...field.RelationField) IPermissionDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Preload(fields ...field.RelationField) IPermissionDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p permissionDo) FirstOrInit() (*model.Permission, error) { | ||||
| 	if result, err := p.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Permission), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p permissionDo) FirstOrCreate() (*model.Permission, error) { | ||||
| 	if result, err := p.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Permission), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p permissionDo) FindByPage(offset int, limit int) (result []*model.Permission, count int64, err error) { | ||||
| 	result, err = p.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 = p.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p permissionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = p.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = p.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Scan(result interface{}) (err error) { | ||||
| 	return p.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (p permissionDo) Delete(models ...*model.Permission) (result gen.ResultInfo, err error) { | ||||
| 	return p.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (p *permissionDo) withDO(do gen.Dao) *permissionDo { | ||||
| 	p.DO = *do.(*gen.DO) | ||||
| 	return p | ||||
| } | ||||
							
								
								
									
										426
									
								
								internal/app/repository/query/process.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										426
									
								
								internal/app/repository/query/process.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,426 @@ | ||||
| // 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 newProcess(db *gorm.DB, opts ...gen.DOOption) process { | ||||
| 	_process := process{} | ||||
|  | ||||
| 	_process.processDo.UseDB(db, opts...) | ||||
| 	_process.processDo.UseModel(&model.Process{}) | ||||
|  | ||||
| 	tableName := _process.processDo.TableName() | ||||
| 	_process.ALL = field.NewAsterisk(tableName) | ||||
| 	_process.Uuid = field.NewInt(tableName, "uuid") | ||||
| 	_process.Name = field.NewString(tableName, "name") | ||||
| 	_process.Cmd = field.NewString(tableName, "args") | ||||
| 	_process.Cwd = field.NewString(tableName, "cwd") | ||||
| 	_process.AutoRestart = field.NewBool(tableName, "auto_restart") | ||||
| 	_process.CompulsoryRestart = field.NewBool(tableName, "compulsory_restart") | ||||
| 	_process.PushIds = field.NewString(tableName, "push_ids") | ||||
| 	_process.LogReport = field.NewBool(tableName, "log_report") | ||||
| 	_process.TermType = field.NewString(tableName, "term_type") | ||||
| 	_process.CgroupEnable = field.NewBool(tableName, "cgroup_enable") | ||||
| 	_process.MemoryLimit = field.NewFloat32(tableName, "memory_limit") | ||||
| 	_process.CpuLimit = field.NewFloat32(tableName, "cpu_limit") | ||||
|  | ||||
| 	_process.fillFieldMap() | ||||
|  | ||||
| 	return _process | ||||
| } | ||||
|  | ||||
| type process struct { | ||||
| 	processDo | ||||
|  | ||||
| 	ALL               field.Asterisk | ||||
| 	Uuid              field.Int | ||||
| 	Name              field.String | ||||
| 	Cmd               field.String | ||||
| 	Cwd               field.String | ||||
| 	AutoRestart       field.Bool | ||||
| 	CompulsoryRestart field.Bool | ||||
| 	PushIds           field.String | ||||
| 	LogReport         field.Bool | ||||
| 	TermType          field.String | ||||
| 	CgroupEnable      field.Bool | ||||
| 	MemoryLimit       field.Float32 | ||||
| 	CpuLimit          field.Float32 | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (p process) Table(newTableName string) *process { | ||||
| 	p.processDo.UseTable(newTableName) | ||||
| 	return p.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (p process) As(alias string) *process { | ||||
| 	p.processDo.DO = *(p.processDo.As(alias).(*gen.DO)) | ||||
| 	return p.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (p *process) updateTableName(table string) *process { | ||||
| 	p.ALL = field.NewAsterisk(table) | ||||
| 	p.Uuid = field.NewInt(table, "uuid") | ||||
| 	p.Name = field.NewString(table, "name") | ||||
| 	p.Cmd = field.NewString(table, "args") | ||||
| 	p.Cwd = field.NewString(table, "cwd") | ||||
| 	p.AutoRestart = field.NewBool(table, "auto_restart") | ||||
| 	p.CompulsoryRestart = field.NewBool(table, "compulsory_restart") | ||||
| 	p.PushIds = field.NewString(table, "push_ids") | ||||
| 	p.LogReport = field.NewBool(table, "log_report") | ||||
| 	p.TermType = field.NewString(table, "term_type") | ||||
| 	p.CgroupEnable = field.NewBool(table, "cgroup_enable") | ||||
| 	p.MemoryLimit = field.NewFloat32(table, "memory_limit") | ||||
| 	p.CpuLimit = field.NewFloat32(table, "cpu_limit") | ||||
|  | ||||
| 	p.fillFieldMap() | ||||
|  | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p *process) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := p.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (p *process) fillFieldMap() { | ||||
| 	p.fieldMap = make(map[string]field.Expr, 12) | ||||
| 	p.fieldMap["uuid"] = p.Uuid | ||||
| 	p.fieldMap["name"] = p.Name | ||||
| 	p.fieldMap["args"] = p.Cmd | ||||
| 	p.fieldMap["cwd"] = p.Cwd | ||||
| 	p.fieldMap["auto_restart"] = p.AutoRestart | ||||
| 	p.fieldMap["compulsory_restart"] = p.CompulsoryRestart | ||||
| 	p.fieldMap["push_ids"] = p.PushIds | ||||
| 	p.fieldMap["log_report"] = p.LogReport | ||||
| 	p.fieldMap["term_type"] = p.TermType | ||||
| 	p.fieldMap["cgroup_enable"] = p.CgroupEnable | ||||
| 	p.fieldMap["memory_limit"] = p.MemoryLimit | ||||
| 	p.fieldMap["cpu_limit"] = p.CpuLimit | ||||
| } | ||||
|  | ||||
| func (p process) clone(db *gorm.DB) process { | ||||
| 	p.processDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p process) replaceDB(db *gorm.DB) process { | ||||
| 	p.processDo.ReplaceDB(db) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| type processDo struct{ gen.DO } | ||||
|  | ||||
| type IProcessDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IProcessDo | ||||
| 	WithContext(ctx context.Context) IProcessDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IProcessDo | ||||
| 	WriteDB() IProcessDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IProcessDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IProcessDo | ||||
| 	Not(conds ...gen.Condition) IProcessDo | ||||
| 	Or(conds ...gen.Condition) IProcessDo | ||||
| 	Select(conds ...field.Expr) IProcessDo | ||||
| 	Where(conds ...gen.Condition) IProcessDo | ||||
| 	Order(conds ...field.Expr) IProcessDo | ||||
| 	Distinct(cols ...field.Expr) IProcessDo | ||||
| 	Omit(cols ...field.Expr) IProcessDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IProcessDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IProcessDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IProcessDo | ||||
| 	Group(cols ...field.Expr) IProcessDo | ||||
| 	Having(conds ...gen.Condition) IProcessDo | ||||
| 	Limit(limit int) IProcessDo | ||||
| 	Offset(offset int) IProcessDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IProcessDo | ||||
| 	Unscoped() IProcessDo | ||||
| 	Create(values ...*model.Process) error | ||||
| 	CreateInBatches(values []*model.Process, batchSize int) error | ||||
| 	Save(values ...*model.Process) error | ||||
| 	First() (*model.Process, error) | ||||
| 	Take() (*model.Process, error) | ||||
| 	Last() (*model.Process, error) | ||||
| 	Find() ([]*model.Process, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Process, err error) | ||||
| 	FindInBatches(result *[]*model.Process, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.Process) (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) IProcessDo | ||||
| 	Assign(attrs ...field.AssignExpr) IProcessDo | ||||
| 	Joins(fields ...field.RelationField) IProcessDo | ||||
| 	Preload(fields ...field.RelationField) IProcessDo | ||||
| 	FirstOrInit() (*model.Process, error) | ||||
| 	FirstOrCreate() (*model.Process, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.Process, 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) IProcessDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (p processDo) Debug() IProcessDo { | ||||
| 	return p.withDO(p.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (p processDo) WithContext(ctx context.Context) IProcessDo { | ||||
| 	return p.withDO(p.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (p processDo) ReadDB() IProcessDo { | ||||
| 	return p.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (p processDo) WriteDB() IProcessDo { | ||||
| 	return p.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (p processDo) Session(config *gorm.Session) IProcessDo { | ||||
| 	return p.withDO(p.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Clauses(conds ...clause.Expression) IProcessDo { | ||||
| 	return p.withDO(p.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Returning(value interface{}, columns ...string) IProcessDo { | ||||
| 	return p.withDO(p.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Not(conds ...gen.Condition) IProcessDo { | ||||
| 	return p.withDO(p.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Or(conds ...gen.Condition) IProcessDo { | ||||
| 	return p.withDO(p.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Select(conds ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Where(conds ...gen.Condition) IProcessDo { | ||||
| 	return p.withDO(p.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Order(conds ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Distinct(cols ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Omit(cols ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Join(table schema.Tabler, on ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) LeftJoin(table schema.Tabler, on ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) RightJoin(table schema.Tabler, on ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Group(cols ...field.Expr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Having(conds ...gen.Condition) IProcessDo { | ||||
| 	return p.withDO(p.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Limit(limit int) IProcessDo { | ||||
| 	return p.withDO(p.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Offset(offset int) IProcessDo { | ||||
| 	return p.withDO(p.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IProcessDo { | ||||
| 	return p.withDO(p.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Unscoped() IProcessDo { | ||||
| 	return p.withDO(p.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (p processDo) Create(values ...*model.Process) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (p processDo) CreateInBatches(values []*model.Process, batchSize int) error { | ||||
| 	return p.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 (p processDo) Save(values ...*model.Process) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (p processDo) First() (*model.Process, error) { | ||||
| 	if result, err := p.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Process), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processDo) Take() (*model.Process, error) { | ||||
| 	if result, err := p.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Process), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processDo) Last() (*model.Process, error) { | ||||
| 	if result, err := p.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Process), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processDo) Find() ([]*model.Process, error) { | ||||
| 	result, err := p.DO.Find() | ||||
| 	return result.([]*model.Process), err | ||||
| } | ||||
|  | ||||
| func (p processDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Process, err error) { | ||||
| 	buf := make([]*model.Process, 0, batchSize) | ||||
| 	err = p.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 (p processDo) FindInBatches(result *[]*model.Process, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return p.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (p processDo) Attrs(attrs ...field.AssignExpr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Assign(attrs ...field.AssignExpr) IProcessDo { | ||||
| 	return p.withDO(p.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p processDo) Joins(fields ...field.RelationField) IProcessDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p processDo) Preload(fields ...field.RelationField) IProcessDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p processDo) FirstOrInit() (*model.Process, error) { | ||||
| 	if result, err := p.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Process), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processDo) FirstOrCreate() (*model.Process, error) { | ||||
| 	if result, err := p.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Process), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processDo) FindByPage(offset int, limit int) (result []*model.Process, count int64, err error) { | ||||
| 	result, err = p.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 = p.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p processDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = p.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = p.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p processDo) Scan(result interface{}) (err error) { | ||||
| 	return p.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (p processDo) Delete(models ...*model.Process) (result gen.ResultInfo, err error) { | ||||
| 	return p.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (p *processDo) withDO(do gen.Dao) *processDo { | ||||
| 	p.DO = *do.(*gen.DO) | ||||
| 	return p | ||||
| } | ||||
							
								
								
									
										398
									
								
								internal/app/repository/query/process_log.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										398
									
								
								internal/app/repository/query/process_log.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 newProcessLog(db *gorm.DB, opts ...gen.DOOption) processLog { | ||||
| 	_processLog := processLog{} | ||||
|  | ||||
| 	_processLog.processLogDo.UseDB(db, opts...) | ||||
| 	_processLog.processLogDo.UseModel(&model.ProcessLog{}) | ||||
|  | ||||
| 	tableName := _processLog.processLogDo.TableName() | ||||
| 	_processLog.ALL = field.NewAsterisk(tableName) | ||||
| 	_processLog.Id = field.NewInt(tableName, "id") | ||||
| 	_processLog.Log = field.NewString(tableName, "log") | ||||
| 	_processLog.Time = field.NewInt64(tableName, "time") | ||||
| 	_processLog.Name = field.NewString(tableName, "name") | ||||
| 	_processLog.Using = field.NewString(tableName, "using") | ||||
|  | ||||
| 	_processLog.fillFieldMap() | ||||
|  | ||||
| 	return _processLog | ||||
| } | ||||
|  | ||||
| type processLog struct { | ||||
| 	processLogDo | ||||
|  | ||||
| 	ALL   field.Asterisk | ||||
| 	Id    field.Int | ||||
| 	Log   field.String | ||||
| 	Time  field.Int64 | ||||
| 	Name  field.String | ||||
| 	Using field.String | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (p processLog) Table(newTableName string) *processLog { | ||||
| 	p.processLogDo.UseTable(newTableName) | ||||
| 	return p.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (p processLog) As(alias string) *processLog { | ||||
| 	p.processLogDo.DO = *(p.processLogDo.As(alias).(*gen.DO)) | ||||
| 	return p.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (p *processLog) updateTableName(table string) *processLog { | ||||
| 	p.ALL = field.NewAsterisk(table) | ||||
| 	p.Id = field.NewInt(table, "id") | ||||
| 	p.Log = field.NewString(table, "log") | ||||
| 	p.Time = field.NewInt64(table, "time") | ||||
| 	p.Name = field.NewString(table, "name") | ||||
| 	p.Using = field.NewString(table, "using") | ||||
|  | ||||
| 	p.fillFieldMap() | ||||
|  | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p *processLog) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := p.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (p *processLog) fillFieldMap() { | ||||
| 	p.fieldMap = make(map[string]field.Expr, 5) | ||||
| 	p.fieldMap["id"] = p.Id | ||||
| 	p.fieldMap["log"] = p.Log | ||||
| 	p.fieldMap["time"] = p.Time | ||||
| 	p.fieldMap["name"] = p.Name | ||||
| 	p.fieldMap["using"] = p.Using | ||||
| } | ||||
|  | ||||
| func (p processLog) clone(db *gorm.DB) processLog { | ||||
| 	p.processLogDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p processLog) replaceDB(db *gorm.DB) processLog { | ||||
| 	p.processLogDo.ReplaceDB(db) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| type processLogDo struct{ gen.DO } | ||||
|  | ||||
| type IProcessLogDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IProcessLogDo | ||||
| 	WithContext(ctx context.Context) IProcessLogDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IProcessLogDo | ||||
| 	WriteDB() IProcessLogDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IProcessLogDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IProcessLogDo | ||||
| 	Not(conds ...gen.Condition) IProcessLogDo | ||||
| 	Or(conds ...gen.Condition) IProcessLogDo | ||||
| 	Select(conds ...field.Expr) IProcessLogDo | ||||
| 	Where(conds ...gen.Condition) IProcessLogDo | ||||
| 	Order(conds ...field.Expr) IProcessLogDo | ||||
| 	Distinct(cols ...field.Expr) IProcessLogDo | ||||
| 	Omit(cols ...field.Expr) IProcessLogDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IProcessLogDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IProcessLogDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IProcessLogDo | ||||
| 	Group(cols ...field.Expr) IProcessLogDo | ||||
| 	Having(conds ...gen.Condition) IProcessLogDo | ||||
| 	Limit(limit int) IProcessLogDo | ||||
| 	Offset(offset int) IProcessLogDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IProcessLogDo | ||||
| 	Unscoped() IProcessLogDo | ||||
| 	Create(values ...*model.ProcessLog) error | ||||
| 	CreateInBatches(values []*model.ProcessLog, batchSize int) error | ||||
| 	Save(values ...*model.ProcessLog) error | ||||
| 	First() (*model.ProcessLog, error) | ||||
| 	Take() (*model.ProcessLog, error) | ||||
| 	Last() (*model.ProcessLog, error) | ||||
| 	Find() ([]*model.ProcessLog, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ProcessLog, err error) | ||||
| 	FindInBatches(result *[]*model.ProcessLog, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.ProcessLog) (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) IProcessLogDo | ||||
| 	Assign(attrs ...field.AssignExpr) IProcessLogDo | ||||
| 	Joins(fields ...field.RelationField) IProcessLogDo | ||||
| 	Preload(fields ...field.RelationField) IProcessLogDo | ||||
| 	FirstOrInit() (*model.ProcessLog, error) | ||||
| 	FirstOrCreate() (*model.ProcessLog, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.ProcessLog, 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) IProcessLogDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Debug() IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) WithContext(ctx context.Context) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) ReadDB() IProcessLogDo { | ||||
| 	return p.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) WriteDB() IProcessLogDo { | ||||
| 	return p.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Session(config *gorm.Session) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Clauses(conds ...clause.Expression) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Returning(value interface{}, columns ...string) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Not(conds ...gen.Condition) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Or(conds ...gen.Condition) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Select(conds ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Where(conds ...gen.Condition) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Order(conds ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Distinct(cols ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Omit(cols ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Join(table schema.Tabler, on ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) LeftJoin(table schema.Tabler, on ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) RightJoin(table schema.Tabler, on ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Group(cols ...field.Expr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Having(conds ...gen.Condition) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Limit(limit int) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Offset(offset int) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Unscoped() IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Create(values ...*model.ProcessLog) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) CreateInBatches(values []*model.ProcessLog, batchSize int) error { | ||||
| 	return p.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 (p processLogDo) Save(values ...*model.ProcessLog) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) First() (*model.ProcessLog, error) { | ||||
| 	if result, err := p.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.ProcessLog), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Take() (*model.ProcessLog, error) { | ||||
| 	if result, err := p.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.ProcessLog), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Last() (*model.ProcessLog, error) { | ||||
| 	if result, err := p.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.ProcessLog), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Find() ([]*model.ProcessLog, error) { | ||||
| 	result, err := p.DO.Find() | ||||
| 	return result.([]*model.ProcessLog), err | ||||
| } | ||||
|  | ||||
| func (p processLogDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.ProcessLog, err error) { | ||||
| 	buf := make([]*model.ProcessLog, 0, batchSize) | ||||
| 	err = p.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 (p processLogDo) FindInBatches(result *[]*model.ProcessLog, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return p.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Attrs(attrs ...field.AssignExpr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Assign(attrs ...field.AssignExpr) IProcessLogDo { | ||||
| 	return p.withDO(p.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Joins(fields ...field.RelationField) IProcessLogDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Preload(fields ...field.RelationField) IProcessLogDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p processLogDo) FirstOrInit() (*model.ProcessLog, error) { | ||||
| 	if result, err := p.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.ProcessLog), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processLogDo) FirstOrCreate() (*model.ProcessLog, error) { | ||||
| 	if result, err := p.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.ProcessLog), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p processLogDo) FindByPage(offset int, limit int) (result []*model.ProcessLog, count int64, err error) { | ||||
| 	result, err = p.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 = p.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p processLogDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = p.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = p.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Scan(result interface{}) (err error) { | ||||
| 	return p.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (p processLogDo) Delete(models ...*model.ProcessLog) (result gen.ResultInfo, err error) { | ||||
| 	return p.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (p *processLogDo) withDO(do gen.Dao) *processLogDo { | ||||
| 	p.DO = *do.(*gen.DO) | ||||
| 	return p | ||||
| } | ||||
							
								
								
									
										402
									
								
								internal/app/repository/query/push.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										402
									
								
								internal/app/repository/query/push.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,402 @@ | ||||
| // 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 newPush(db *gorm.DB, opts ...gen.DOOption) push { | ||||
| 	_push := push{} | ||||
|  | ||||
| 	_push.pushDo.UseDB(db, opts...) | ||||
| 	_push.pushDo.UseModel(&model.Push{}) | ||||
|  | ||||
| 	tableName := _push.pushDo.TableName() | ||||
| 	_push.ALL = field.NewAsterisk(tableName) | ||||
| 	_push.Id = field.NewInt64(tableName, "id") | ||||
| 	_push.Method = field.NewString(tableName, "method") | ||||
| 	_push.Url = field.NewString(tableName, "url") | ||||
| 	_push.Body = field.NewString(tableName, "body") | ||||
| 	_push.Remark = field.NewString(tableName, "remark") | ||||
| 	_push.Enable = field.NewBool(tableName, "enable") | ||||
|  | ||||
| 	_push.fillFieldMap() | ||||
|  | ||||
| 	return _push | ||||
| } | ||||
|  | ||||
| type push struct { | ||||
| 	pushDo | ||||
|  | ||||
| 	ALL    field.Asterisk | ||||
| 	Id     field.Int64 | ||||
| 	Method field.String | ||||
| 	Url    field.String | ||||
| 	Body   field.String | ||||
| 	Remark field.String | ||||
| 	Enable field.Bool | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (p push) Table(newTableName string) *push { | ||||
| 	p.pushDo.UseTable(newTableName) | ||||
| 	return p.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (p push) As(alias string) *push { | ||||
| 	p.pushDo.DO = *(p.pushDo.As(alias).(*gen.DO)) | ||||
| 	return p.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (p *push) updateTableName(table string) *push { | ||||
| 	p.ALL = field.NewAsterisk(table) | ||||
| 	p.Id = field.NewInt64(table, "id") | ||||
| 	p.Method = field.NewString(table, "method") | ||||
| 	p.Url = field.NewString(table, "url") | ||||
| 	p.Body = field.NewString(table, "body") | ||||
| 	p.Remark = field.NewString(table, "remark") | ||||
| 	p.Enable = field.NewBool(table, "enable") | ||||
|  | ||||
| 	p.fillFieldMap() | ||||
|  | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p *push) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := p.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (p *push) fillFieldMap() { | ||||
| 	p.fieldMap = make(map[string]field.Expr, 6) | ||||
| 	p.fieldMap["id"] = p.Id | ||||
| 	p.fieldMap["method"] = p.Method | ||||
| 	p.fieldMap["url"] = p.Url | ||||
| 	p.fieldMap["body"] = p.Body | ||||
| 	p.fieldMap["remark"] = p.Remark | ||||
| 	p.fieldMap["enable"] = p.Enable | ||||
| } | ||||
|  | ||||
| func (p push) clone(db *gorm.DB) push { | ||||
| 	p.pushDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| func (p push) replaceDB(db *gorm.DB) push { | ||||
| 	p.pushDo.ReplaceDB(db) | ||||
| 	return p | ||||
| } | ||||
|  | ||||
| type pushDo struct{ gen.DO } | ||||
|  | ||||
| type IPushDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IPushDo | ||||
| 	WithContext(ctx context.Context) IPushDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IPushDo | ||||
| 	WriteDB() IPushDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IPushDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IPushDo | ||||
| 	Not(conds ...gen.Condition) IPushDo | ||||
| 	Or(conds ...gen.Condition) IPushDo | ||||
| 	Select(conds ...field.Expr) IPushDo | ||||
| 	Where(conds ...gen.Condition) IPushDo | ||||
| 	Order(conds ...field.Expr) IPushDo | ||||
| 	Distinct(cols ...field.Expr) IPushDo | ||||
| 	Omit(cols ...field.Expr) IPushDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IPushDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IPushDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IPushDo | ||||
| 	Group(cols ...field.Expr) IPushDo | ||||
| 	Having(conds ...gen.Condition) IPushDo | ||||
| 	Limit(limit int) IPushDo | ||||
| 	Offset(offset int) IPushDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IPushDo | ||||
| 	Unscoped() IPushDo | ||||
| 	Create(values ...*model.Push) error | ||||
| 	CreateInBatches(values []*model.Push, batchSize int) error | ||||
| 	Save(values ...*model.Push) error | ||||
| 	First() (*model.Push, error) | ||||
| 	Take() (*model.Push, error) | ||||
| 	Last() (*model.Push, error) | ||||
| 	Find() ([]*model.Push, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Push, err error) | ||||
| 	FindInBatches(result *[]*model.Push, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.Push) (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) IPushDo | ||||
| 	Assign(attrs ...field.AssignExpr) IPushDo | ||||
| 	Joins(fields ...field.RelationField) IPushDo | ||||
| 	Preload(fields ...field.RelationField) IPushDo | ||||
| 	FirstOrInit() (*model.Push, error) | ||||
| 	FirstOrCreate() (*model.Push, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.Push, 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) IPushDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (p pushDo) Debug() IPushDo { | ||||
| 	return p.withDO(p.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (p pushDo) WithContext(ctx context.Context) IPushDo { | ||||
| 	return p.withDO(p.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) ReadDB() IPushDo { | ||||
| 	return p.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (p pushDo) WriteDB() IPushDo { | ||||
| 	return p.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Session(config *gorm.Session) IPushDo { | ||||
| 	return p.withDO(p.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Clauses(conds ...clause.Expression) IPushDo { | ||||
| 	return p.withDO(p.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Returning(value interface{}, columns ...string) IPushDo { | ||||
| 	return p.withDO(p.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Not(conds ...gen.Condition) IPushDo { | ||||
| 	return p.withDO(p.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Or(conds ...gen.Condition) IPushDo { | ||||
| 	return p.withDO(p.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Select(conds ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Where(conds ...gen.Condition) IPushDo { | ||||
| 	return p.withDO(p.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Order(conds ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Distinct(cols ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Omit(cols ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Join(table schema.Tabler, on ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) RightJoin(table schema.Tabler, on ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Group(cols ...field.Expr) IPushDo { | ||||
| 	return p.withDO(p.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Having(conds ...gen.Condition) IPushDo { | ||||
| 	return p.withDO(p.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Limit(limit int) IPushDo { | ||||
| 	return p.withDO(p.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Offset(offset int) IPushDo { | ||||
| 	return p.withDO(p.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPushDo { | ||||
| 	return p.withDO(p.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Unscoped() IPushDo { | ||||
| 	return p.withDO(p.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Create(values ...*model.Push) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (p pushDo) CreateInBatches(values []*model.Push, batchSize int) error { | ||||
| 	return p.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 (p pushDo) Save(values ...*model.Push) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return p.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (p pushDo) First() (*model.Push, error) { | ||||
| 	if result, err := p.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Push), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p pushDo) Take() (*model.Push, error) { | ||||
| 	if result, err := p.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Push), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p pushDo) Last() (*model.Push, error) { | ||||
| 	if result, err := p.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Push), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p pushDo) Find() ([]*model.Push, error) { | ||||
| 	result, err := p.DO.Find() | ||||
| 	return result.([]*model.Push), err | ||||
| } | ||||
|  | ||||
| func (p pushDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Push, err error) { | ||||
| 	buf := make([]*model.Push, 0, batchSize) | ||||
| 	err = p.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 (p pushDo) FindInBatches(result *[]*model.Push, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return p.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Attrs(attrs ...field.AssignExpr) IPushDo { | ||||
| 	return p.withDO(p.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Assign(attrs ...field.AssignExpr) IPushDo { | ||||
| 	return p.withDO(p.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Joins(fields ...field.RelationField) IPushDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p pushDo) Preload(fields ...field.RelationField) IPushDo { | ||||
| 	for _, _f := range fields { | ||||
| 		p = *p.withDO(p.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &p | ||||
| } | ||||
|  | ||||
| func (p pushDo) FirstOrInit() (*model.Push, error) { | ||||
| 	if result, err := p.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Push), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p pushDo) FirstOrCreate() (*model.Push, error) { | ||||
| 	if result, err := p.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Push), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (p pushDo) FindByPage(offset int, limit int) (result []*model.Push, count int64, err error) { | ||||
| 	result, err = p.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 = p.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p pushDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = p.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = p.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p pushDo) Scan(result interface{}) (err error) { | ||||
| 	return p.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (p pushDo) Delete(models ...*model.Push) (result gen.ResultInfo, err error) { | ||||
| 	return p.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (p *pushDo) withDO(do gen.Dao) *pushDo { | ||||
| 	p.DO = *do.(*gen.DO) | ||||
| 	return p | ||||
| } | ||||
							
								
								
									
										430
									
								
								internal/app/repository/query/task.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										430
									
								
								internal/app/repository/query/task.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,430 @@ | ||||
| // 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 newTask(db *gorm.DB, opts ...gen.DOOption) task { | ||||
| 	_task := task{} | ||||
|  | ||||
| 	_task.taskDo.UseDB(db, opts...) | ||||
| 	_task.taskDo.UseModel(&model.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") | ||||
| 	_task.Operation = field.NewInt(tableName, "operation") | ||||
| 	_task.TriggerEvent = field.NewInt32(tableName, "trigger_event") | ||||
| 	_task.TriggerTarget = field.NewInt(tableName, "trigger_target") | ||||
| 	_task.OperationTarget = field.NewInt(tableName, "operation_target") | ||||
| 	_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") | ||||
|  | ||||
| 	_task.fillFieldMap() | ||||
|  | ||||
| 	return _task | ||||
| } | ||||
|  | ||||
| type task struct { | ||||
| 	taskDo | ||||
|  | ||||
| 	ALL             field.Asterisk | ||||
| 	Id              field.Int | ||||
| 	Name            field.String | ||||
| 	ProcessId       field.Int | ||||
| 	Condition       field.Int | ||||
| 	NextId          field.Int | ||||
| 	Operation       field.Int | ||||
| 	TriggerEvent    field.Int32 | ||||
| 	TriggerTarget   field.Int | ||||
| 	OperationTarget field.Int | ||||
| 	CronExpression  field.String | ||||
| 	Enable          field.Bool | ||||
| 	ApiEnable       field.Bool | ||||
| 	Key             field.String | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (t task) Table(newTableName string) *task { | ||||
| 	t.taskDo.UseTable(newTableName) | ||||
| 	return t.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (t task) As(alias string) *task { | ||||
| 	t.taskDo.DO = *(t.taskDo.As(alias).(*gen.DO)) | ||||
| 	return t.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| 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") | ||||
| 	t.Operation = field.NewInt(table, "operation") | ||||
| 	t.TriggerEvent = field.NewInt32(table, "trigger_event") | ||||
| 	t.TriggerTarget = field.NewInt(table, "trigger_target") | ||||
| 	t.OperationTarget = field.NewInt(table, "operation_target") | ||||
| 	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") | ||||
|  | ||||
| 	t.fillFieldMap() | ||||
|  | ||||
| 	return t | ||||
| } | ||||
|  | ||||
| func (t *task) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := t.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (t *task) fillFieldMap() { | ||||
| 	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 | ||||
| 	t.fieldMap["operation"] = t.Operation | ||||
| 	t.fieldMap["trigger_event"] = t.TriggerEvent | ||||
| 	t.fieldMap["trigger_target"] = t.TriggerTarget | ||||
| 	t.fieldMap["operation_target"] = t.OperationTarget | ||||
| 	t.fieldMap["cron"] = t.CronExpression | ||||
| 	t.fieldMap["enable"] = t.Enable | ||||
| 	t.fieldMap["api_enable"] = t.ApiEnable | ||||
| 	t.fieldMap["key"] = t.Key | ||||
| } | ||||
|  | ||||
| func (t task) clone(db *gorm.DB) task { | ||||
| 	t.taskDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return t | ||||
| } | ||||
|  | ||||
| func (t task) replaceDB(db *gorm.DB) task { | ||||
| 	t.taskDo.ReplaceDB(db) | ||||
| 	return t | ||||
| } | ||||
|  | ||||
| type taskDo struct{ gen.DO } | ||||
|  | ||||
| type ITaskDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() ITaskDo | ||||
| 	WithContext(ctx context.Context) ITaskDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() ITaskDo | ||||
| 	WriteDB() ITaskDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) ITaskDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) ITaskDo | ||||
| 	Not(conds ...gen.Condition) ITaskDo | ||||
| 	Or(conds ...gen.Condition) ITaskDo | ||||
| 	Select(conds ...field.Expr) ITaskDo | ||||
| 	Where(conds ...gen.Condition) ITaskDo | ||||
| 	Order(conds ...field.Expr) ITaskDo | ||||
| 	Distinct(cols ...field.Expr) ITaskDo | ||||
| 	Omit(cols ...field.Expr) ITaskDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) ITaskDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) ITaskDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) ITaskDo | ||||
| 	Group(cols ...field.Expr) ITaskDo | ||||
| 	Having(conds ...gen.Condition) ITaskDo | ||||
| 	Limit(limit int) ITaskDo | ||||
| 	Offset(offset int) ITaskDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) ITaskDo | ||||
| 	Unscoped() ITaskDo | ||||
| 	Create(values ...*model.Task) error | ||||
| 	CreateInBatches(values []*model.Task, batchSize int) error | ||||
| 	Save(values ...*model.Task) error | ||||
| 	First() (*model.Task, error) | ||||
| 	Take() (*model.Task, error) | ||||
| 	Last() (*model.Task, error) | ||||
| 	Find() ([]*model.Task, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Task, err error) | ||||
| 	FindInBatches(result *[]*model.Task, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.Task) (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) ITaskDo | ||||
| 	Assign(attrs ...field.AssignExpr) ITaskDo | ||||
| 	Joins(fields ...field.RelationField) ITaskDo | ||||
| 	Preload(fields ...field.RelationField) ITaskDo | ||||
| 	FirstOrInit() (*model.Task, error) | ||||
| 	FirstOrCreate() (*model.Task, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.Task, 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) ITaskDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (t taskDo) Debug() ITaskDo { | ||||
| 	return t.withDO(t.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (t taskDo) WithContext(ctx context.Context) ITaskDo { | ||||
| 	return t.withDO(t.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) ReadDB() ITaskDo { | ||||
| 	return t.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (t taskDo) WriteDB() ITaskDo { | ||||
| 	return t.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Session(config *gorm.Session) ITaskDo { | ||||
| 	return t.withDO(t.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Clauses(conds ...clause.Expression) ITaskDo { | ||||
| 	return t.withDO(t.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Returning(value interface{}, columns ...string) ITaskDo { | ||||
| 	return t.withDO(t.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Not(conds ...gen.Condition) ITaskDo { | ||||
| 	return t.withDO(t.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Or(conds ...gen.Condition) ITaskDo { | ||||
| 	return t.withDO(t.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Select(conds ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Where(conds ...gen.Condition) ITaskDo { | ||||
| 	return t.withDO(t.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Order(conds ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Distinct(cols ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Omit(cols ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Join(table schema.Tabler, on ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) LeftJoin(table schema.Tabler, on ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) RightJoin(table schema.Tabler, on ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Group(cols ...field.Expr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Having(conds ...gen.Condition) ITaskDo { | ||||
| 	return t.withDO(t.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Limit(limit int) ITaskDo { | ||||
| 	return t.withDO(t.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Offset(offset int) ITaskDo { | ||||
| 	return t.withDO(t.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ITaskDo { | ||||
| 	return t.withDO(t.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Unscoped() ITaskDo { | ||||
| 	return t.withDO(t.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Create(values ...*model.Task) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return t.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (t taskDo) CreateInBatches(values []*model.Task, batchSize int) error { | ||||
| 	return t.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 (t taskDo) Save(values ...*model.Task) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return t.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (t taskDo) First() (*model.Task, error) { | ||||
| 	if result, err := t.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Task), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t taskDo) Take() (*model.Task, error) { | ||||
| 	if result, err := t.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Task), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t taskDo) Last() (*model.Task, error) { | ||||
| 	if result, err := t.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Task), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t taskDo) Find() ([]*model.Task, error) { | ||||
| 	result, err := t.DO.Find() | ||||
| 	return result.([]*model.Task), err | ||||
| } | ||||
|  | ||||
| func (t taskDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Task, err error) { | ||||
| 	buf := make([]*model.Task, 0, batchSize) | ||||
| 	err = t.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 (t taskDo) FindInBatches(result *[]*model.Task, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return t.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Attrs(attrs ...field.AssignExpr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Assign(attrs ...field.AssignExpr) ITaskDo { | ||||
| 	return t.withDO(t.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Joins(fields ...field.RelationField) ITaskDo { | ||||
| 	for _, _f := range fields { | ||||
| 		t = *t.withDO(t.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &t | ||||
| } | ||||
|  | ||||
| func (t taskDo) Preload(fields ...field.RelationField) ITaskDo { | ||||
| 	for _, _f := range fields { | ||||
| 		t = *t.withDO(t.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &t | ||||
| } | ||||
|  | ||||
| func (t taskDo) FirstOrInit() (*model.Task, error) { | ||||
| 	if result, err := t.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Task), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t taskDo) FirstOrCreate() (*model.Task, error) { | ||||
| 	if result, err := t.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.Task), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (t taskDo) FindByPage(offset int, limit int) (result []*model.Task, count int64, err error) { | ||||
| 	result, err = t.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 = t.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (t taskDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = t.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = t.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (t taskDo) Scan(result interface{}) (err error) { | ||||
| 	return t.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (t taskDo) Delete(models ...*model.Task) (result gen.ResultInfo, err error) { | ||||
| 	return t.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (t *taskDo) withDO(do gen.Dao) *taskDo { | ||||
| 	t.DO = *do.(*gen.DO) | ||||
| 	return t | ||||
| } | ||||
							
								
								
									
										398
									
								
								internal/app/repository/query/users.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										398
									
								
								internal/app/repository/query/users.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 newUser(db *gorm.DB, opts ...gen.DOOption) user { | ||||
| 	_user := user{} | ||||
|  | ||||
| 	_user.userDo.UseDB(db, opts...) | ||||
| 	_user.userDo.UseModel(&model.User{}) | ||||
|  | ||||
| 	tableName := _user.userDo.TableName() | ||||
| 	_user.ALL = field.NewAsterisk(tableName) | ||||
| 	_user.Account = field.NewString(tableName, "account") | ||||
| 	_user.Password = field.NewString(tableName, "password") | ||||
| 	_user.Role = field.NewInt(tableName, "role") | ||||
| 	_user.CreateTime = field.NewTime(tableName, "create_time") | ||||
| 	_user.Remark = field.NewString(tableName, "remark") | ||||
|  | ||||
| 	_user.fillFieldMap() | ||||
|  | ||||
| 	return _user | ||||
| } | ||||
|  | ||||
| type user struct { | ||||
| 	userDo | ||||
|  | ||||
| 	ALL        field.Asterisk | ||||
| 	Account    field.String | ||||
| 	Password   field.String | ||||
| 	Role       field.Int | ||||
| 	CreateTime field.Time | ||||
| 	Remark     field.String | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (u user) Table(newTableName string) *user { | ||||
| 	u.userDo.UseTable(newTableName) | ||||
| 	return u.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (u user) As(alias string) *user { | ||||
| 	u.userDo.DO = *(u.userDo.As(alias).(*gen.DO)) | ||||
| 	return u.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (u *user) updateTableName(table string) *user { | ||||
| 	u.ALL = field.NewAsterisk(table) | ||||
| 	u.Account = field.NewString(table, "account") | ||||
| 	u.Password = field.NewString(table, "password") | ||||
| 	u.Role = field.NewInt(table, "role") | ||||
| 	u.CreateTime = field.NewTime(table, "create_time") | ||||
| 	u.Remark = field.NewString(table, "remark") | ||||
|  | ||||
| 	u.fillFieldMap() | ||||
|  | ||||
| 	return u | ||||
| } | ||||
|  | ||||
| func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := u.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (u *user) fillFieldMap() { | ||||
| 	u.fieldMap = make(map[string]field.Expr, 5) | ||||
| 	u.fieldMap["account"] = u.Account | ||||
| 	u.fieldMap["password"] = u.Password | ||||
| 	u.fieldMap["role"] = u.Role | ||||
| 	u.fieldMap["create_time"] = u.CreateTime | ||||
| 	u.fieldMap["remark"] = u.Remark | ||||
| } | ||||
|  | ||||
| func (u user) clone(db *gorm.DB) user { | ||||
| 	u.userDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return u | ||||
| } | ||||
|  | ||||
| func (u user) replaceDB(db *gorm.DB) user { | ||||
| 	u.userDo.ReplaceDB(db) | ||||
| 	return u | ||||
| } | ||||
|  | ||||
| type userDo struct{ gen.DO } | ||||
|  | ||||
| type IUserDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IUserDo | ||||
| 	WithContext(ctx context.Context) IUserDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IUserDo | ||||
| 	WriteDB() IUserDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IUserDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IUserDo | ||||
| 	Not(conds ...gen.Condition) IUserDo | ||||
| 	Or(conds ...gen.Condition) IUserDo | ||||
| 	Select(conds ...field.Expr) IUserDo | ||||
| 	Where(conds ...gen.Condition) IUserDo | ||||
| 	Order(conds ...field.Expr) IUserDo | ||||
| 	Distinct(cols ...field.Expr) IUserDo | ||||
| 	Omit(cols ...field.Expr) IUserDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IUserDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IUserDo | ||||
| 	Group(cols ...field.Expr) IUserDo | ||||
| 	Having(conds ...gen.Condition) IUserDo | ||||
| 	Limit(limit int) IUserDo | ||||
| 	Offset(offset int) IUserDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo | ||||
| 	Unscoped() IUserDo | ||||
| 	Create(values ...*model.User) error | ||||
| 	CreateInBatches(values []*model.User, batchSize int) error | ||||
| 	Save(values ...*model.User) error | ||||
| 	First() (*model.User, error) | ||||
| 	Take() (*model.User, error) | ||||
| 	Last() (*model.User, error) | ||||
| 	Find() ([]*model.User, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.User, err error) | ||||
| 	FindInBatches(result *[]*model.User, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.User) (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) IUserDo | ||||
| 	Assign(attrs ...field.AssignExpr) IUserDo | ||||
| 	Joins(fields ...field.RelationField) IUserDo | ||||
| 	Preload(fields ...field.RelationField) IUserDo | ||||
| 	FirstOrInit() (*model.User, error) | ||||
| 	FirstOrCreate() (*model.User, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.User, 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) IUserDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (u userDo) Debug() IUserDo { | ||||
| 	return u.withDO(u.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (u userDo) WithContext(ctx context.Context) IUserDo { | ||||
| 	return u.withDO(u.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (u userDo) ReadDB() IUserDo { | ||||
| 	return u.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (u userDo) WriteDB() IUserDo { | ||||
| 	return u.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (u userDo) Session(config *gorm.Session) IUserDo { | ||||
| 	return u.withDO(u.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Clauses(conds ...clause.Expression) IUserDo { | ||||
| 	return u.withDO(u.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Returning(value interface{}, columns ...string) IUserDo { | ||||
| 	return u.withDO(u.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Not(conds ...gen.Condition) IUserDo { | ||||
| 	return u.withDO(u.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Or(conds ...gen.Condition) IUserDo { | ||||
| 	return u.withDO(u.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Select(conds ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Where(conds ...gen.Condition) IUserDo { | ||||
| 	return u.withDO(u.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Order(conds ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Distinct(cols ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Omit(cols ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Join(table schema.Tabler, on ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Group(cols ...field.Expr) IUserDo { | ||||
| 	return u.withDO(u.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Having(conds ...gen.Condition) IUserDo { | ||||
| 	return u.withDO(u.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Limit(limit int) IUserDo { | ||||
| 	return u.withDO(u.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Offset(offset int) IUserDo { | ||||
| 	return u.withDO(u.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserDo { | ||||
| 	return u.withDO(u.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Unscoped() IUserDo { | ||||
| 	return u.withDO(u.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (u userDo) Create(values ...*model.User) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return u.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (u userDo) CreateInBatches(values []*model.User, batchSize int) error { | ||||
| 	return u.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 (u userDo) Save(values ...*model.User) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return u.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (u userDo) First() (*model.User, error) { | ||||
| 	if result, err := u.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.User), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u userDo) Take() (*model.User, error) { | ||||
| 	if result, err := u.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.User), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u userDo) Last() (*model.User, error) { | ||||
| 	if result, err := u.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.User), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u userDo) Find() ([]*model.User, error) { | ||||
| 	result, err := u.DO.Find() | ||||
| 	return result.([]*model.User), err | ||||
| } | ||||
|  | ||||
| func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.User, err error) { | ||||
| 	buf := make([]*model.User, 0, batchSize) | ||||
| 	err = u.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 (u userDo) FindInBatches(result *[]*model.User, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return u.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (u userDo) Attrs(attrs ...field.AssignExpr) IUserDo { | ||||
| 	return u.withDO(u.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Assign(attrs ...field.AssignExpr) IUserDo { | ||||
| 	return u.withDO(u.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (u userDo) Joins(fields ...field.RelationField) IUserDo { | ||||
| 	for _, _f := range fields { | ||||
| 		u = *u.withDO(u.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &u | ||||
| } | ||||
|  | ||||
| func (u userDo) Preload(fields ...field.RelationField) IUserDo { | ||||
| 	for _, _f := range fields { | ||||
| 		u = *u.withDO(u.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &u | ||||
| } | ||||
|  | ||||
| func (u userDo) FirstOrInit() (*model.User, error) { | ||||
| 	if result, err := u.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.User), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u userDo) FirstOrCreate() (*model.User, error) { | ||||
| 	if result, err := u.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.User), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (u userDo) FindByPage(offset int, limit int) (result []*model.User, count int64, err error) { | ||||
| 	result, err = u.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 = u.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = u.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = u.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (u userDo) Scan(result interface{}) (err error) { | ||||
| 	return u.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (u userDo) Delete(models ...*model.User) (result gen.ResultInfo, err error) { | ||||
| 	return u.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (u *userDo) withDO(do gen.Dao) *userDo { | ||||
| 	u.DO = *do.(*gen.DO) | ||||
| 	return u | ||||
| } | ||||
							
								
								
									
										414
									
								
								internal/app/repository/query/ws_share.gen.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										414
									
								
								internal/app/repository/query/ws_share.gen.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,414 @@ | ||||
| // 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 newWsShare(db *gorm.DB, opts ...gen.DOOption) wsShare { | ||||
| 	_wsShare := wsShare{} | ||||
|  | ||||
| 	_wsShare.wsShareDo.UseDB(db, opts...) | ||||
| 	_wsShare.wsShareDo.UseModel(&model.WsShare{}) | ||||
|  | ||||
| 	tableName := _wsShare.wsShareDo.TableName() | ||||
| 	_wsShare.ALL = field.NewAsterisk(tableName) | ||||
| 	_wsShare.ID = field.NewUint(tableName, "id") | ||||
| 	_wsShare.CreatedAt = field.NewTime(tableName, "created_at") | ||||
| 	_wsShare.UpdatedAt = field.NewTime(tableName, "updated_at") | ||||
| 	_wsShare.DeletedAt = field.NewField(tableName, "deleted_at") | ||||
| 	_wsShare.Pid = field.NewInt(tableName, "pid") | ||||
| 	_wsShare.Write = field.NewBool(tableName, "write") | ||||
| 	_wsShare.ExpireTime = field.NewTime(tableName, "expire_time") | ||||
| 	_wsShare.CreateBy = field.NewString(tableName, "create_by") | ||||
| 	_wsShare.Token = field.NewString(tableName, "token") | ||||
|  | ||||
| 	_wsShare.fillFieldMap() | ||||
|  | ||||
| 	return _wsShare | ||||
| } | ||||
|  | ||||
| type wsShare struct { | ||||
| 	wsShareDo | ||||
|  | ||||
| 	ALL        field.Asterisk | ||||
| 	ID         field.Uint | ||||
| 	CreatedAt  field.Time | ||||
| 	UpdatedAt  field.Time | ||||
| 	DeletedAt  field.Field | ||||
| 	Pid        field.Int | ||||
| 	Write      field.Bool | ||||
| 	ExpireTime field.Time | ||||
| 	CreateBy   field.String | ||||
| 	Token      field.String | ||||
|  | ||||
| 	fieldMap map[string]field.Expr | ||||
| } | ||||
|  | ||||
| func (w wsShare) Table(newTableName string) *wsShare { | ||||
| 	w.wsShareDo.UseTable(newTableName) | ||||
| 	return w.updateTableName(newTableName) | ||||
| } | ||||
|  | ||||
| func (w wsShare) As(alias string) *wsShare { | ||||
| 	w.wsShareDo.DO = *(w.wsShareDo.As(alias).(*gen.DO)) | ||||
| 	return w.updateTableName(alias) | ||||
| } | ||||
|  | ||||
| func (w *wsShare) updateTableName(table string) *wsShare { | ||||
| 	w.ALL = field.NewAsterisk(table) | ||||
| 	w.ID = field.NewUint(table, "id") | ||||
| 	w.CreatedAt = field.NewTime(table, "created_at") | ||||
| 	w.UpdatedAt = field.NewTime(table, "updated_at") | ||||
| 	w.DeletedAt = field.NewField(table, "deleted_at") | ||||
| 	w.Pid = field.NewInt(table, "pid") | ||||
| 	w.Write = field.NewBool(table, "write") | ||||
| 	w.ExpireTime = field.NewTime(table, "expire_time") | ||||
| 	w.CreateBy = field.NewString(table, "create_by") | ||||
| 	w.Token = field.NewString(table, "token") | ||||
|  | ||||
| 	w.fillFieldMap() | ||||
|  | ||||
| 	return w | ||||
| } | ||||
|  | ||||
| func (w *wsShare) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | ||||
| 	_f, ok := w.fieldMap[fieldName] | ||||
| 	if !ok || _f == nil { | ||||
| 		return nil, false | ||||
| 	} | ||||
| 	_oe, ok := _f.(field.OrderExpr) | ||||
| 	return _oe, ok | ||||
| } | ||||
|  | ||||
| func (w *wsShare) fillFieldMap() { | ||||
| 	w.fieldMap = make(map[string]field.Expr, 9) | ||||
| 	w.fieldMap["id"] = w.ID | ||||
| 	w.fieldMap["created_at"] = w.CreatedAt | ||||
| 	w.fieldMap["updated_at"] = w.UpdatedAt | ||||
| 	w.fieldMap["deleted_at"] = w.DeletedAt | ||||
| 	w.fieldMap["pid"] = w.Pid | ||||
| 	w.fieldMap["write"] = w.Write | ||||
| 	w.fieldMap["expire_time"] = w.ExpireTime | ||||
| 	w.fieldMap["create_by"] = w.CreateBy | ||||
| 	w.fieldMap["token"] = w.Token | ||||
| } | ||||
|  | ||||
| func (w wsShare) clone(db *gorm.DB) wsShare { | ||||
| 	w.wsShareDo.ReplaceConnPool(db.Statement.ConnPool) | ||||
| 	return w | ||||
| } | ||||
|  | ||||
| func (w wsShare) replaceDB(db *gorm.DB) wsShare { | ||||
| 	w.wsShareDo.ReplaceDB(db) | ||||
| 	return w | ||||
| } | ||||
|  | ||||
| type wsShareDo struct{ gen.DO } | ||||
|  | ||||
| type IWsShareDo interface { | ||||
| 	gen.SubQuery | ||||
| 	Debug() IWsShareDo | ||||
| 	WithContext(ctx context.Context) IWsShareDo | ||||
| 	WithResult(fc func(tx gen.Dao)) gen.ResultInfo | ||||
| 	ReplaceDB(db *gorm.DB) | ||||
| 	ReadDB() IWsShareDo | ||||
| 	WriteDB() IWsShareDo | ||||
| 	As(alias string) gen.Dao | ||||
| 	Session(config *gorm.Session) IWsShareDo | ||||
| 	Columns(cols ...field.Expr) gen.Columns | ||||
| 	Clauses(conds ...clause.Expression) IWsShareDo | ||||
| 	Not(conds ...gen.Condition) IWsShareDo | ||||
| 	Or(conds ...gen.Condition) IWsShareDo | ||||
| 	Select(conds ...field.Expr) IWsShareDo | ||||
| 	Where(conds ...gen.Condition) IWsShareDo | ||||
| 	Order(conds ...field.Expr) IWsShareDo | ||||
| 	Distinct(cols ...field.Expr) IWsShareDo | ||||
| 	Omit(cols ...field.Expr) IWsShareDo | ||||
| 	Join(table schema.Tabler, on ...field.Expr) IWsShareDo | ||||
| 	LeftJoin(table schema.Tabler, on ...field.Expr) IWsShareDo | ||||
| 	RightJoin(table schema.Tabler, on ...field.Expr) IWsShareDo | ||||
| 	Group(cols ...field.Expr) IWsShareDo | ||||
| 	Having(conds ...gen.Condition) IWsShareDo | ||||
| 	Limit(limit int) IWsShareDo | ||||
| 	Offset(offset int) IWsShareDo | ||||
| 	Count() (count int64, err error) | ||||
| 	Scopes(funcs ...func(gen.Dao) gen.Dao) IWsShareDo | ||||
| 	Unscoped() IWsShareDo | ||||
| 	Create(values ...*model.WsShare) error | ||||
| 	CreateInBatches(values []*model.WsShare, batchSize int) error | ||||
| 	Save(values ...*model.WsShare) error | ||||
| 	First() (*model.WsShare, error) | ||||
| 	Take() (*model.WsShare, error) | ||||
| 	Last() (*model.WsShare, error) | ||||
| 	Find() ([]*model.WsShare, error) | ||||
| 	FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.WsShare, err error) | ||||
| 	FindInBatches(result *[]*model.WsShare, batchSize int, fc func(tx gen.Dao, batch int) error) error | ||||
| 	Pluck(column field.Expr, dest interface{}) error | ||||
| 	Delete(...*model.WsShare) (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) IWsShareDo | ||||
| 	Assign(attrs ...field.AssignExpr) IWsShareDo | ||||
| 	Joins(fields ...field.RelationField) IWsShareDo | ||||
| 	Preload(fields ...field.RelationField) IWsShareDo | ||||
| 	FirstOrInit() (*model.WsShare, error) | ||||
| 	FirstOrCreate() (*model.WsShare, error) | ||||
| 	FindByPage(offset int, limit int) (result []*model.WsShare, 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) IWsShareDo | ||||
| 	UnderlyingDB() *gorm.DB | ||||
| 	schema.Tabler | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Debug() IWsShareDo { | ||||
| 	return w.withDO(w.DO.Debug()) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) WithContext(ctx context.Context) IWsShareDo { | ||||
| 	return w.withDO(w.DO.WithContext(ctx)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) ReadDB() IWsShareDo { | ||||
| 	return w.Clauses(dbresolver.Read) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) WriteDB() IWsShareDo { | ||||
| 	return w.Clauses(dbresolver.Write) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Session(config *gorm.Session) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Session(config)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Clauses(conds ...clause.Expression) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Clauses(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Returning(value interface{}, columns ...string) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Returning(value, columns...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Not(conds ...gen.Condition) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Not(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Or(conds ...gen.Condition) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Or(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Select(conds ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Select(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Where(conds ...gen.Condition) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Where(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Order(conds ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Order(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Distinct(cols ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Distinct(cols...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Omit(cols ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Omit(cols...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Join(table schema.Tabler, on ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Join(table, on...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) LeftJoin(table schema.Tabler, on ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.LeftJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) RightJoin(table schema.Tabler, on ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.RightJoin(table, on...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Group(cols ...field.Expr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Group(cols...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Having(conds ...gen.Condition) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Having(conds...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Limit(limit int) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Limit(limit)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Offset(offset int) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Offset(offset)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Scopes(funcs...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Unscoped() IWsShareDo { | ||||
| 	return w.withDO(w.DO.Unscoped()) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Create(values ...*model.WsShare) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return w.DO.Create(values) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) CreateInBatches(values []*model.WsShare, batchSize int) error { | ||||
| 	return w.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 (w wsShareDo) Save(values ...*model.WsShare) error { | ||||
| 	if len(values) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 	return w.DO.Save(values) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) First() (*model.WsShare, error) { | ||||
| 	if result, err := w.DO.First(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.WsShare), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Take() (*model.WsShare, error) { | ||||
| 	if result, err := w.DO.Take(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.WsShare), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Last() (*model.WsShare, error) { | ||||
| 	if result, err := w.DO.Last(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.WsShare), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Find() ([]*model.WsShare, error) { | ||||
| 	result, err := w.DO.Find() | ||||
| 	return result.([]*model.WsShare), err | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.WsShare, err error) { | ||||
| 	buf := make([]*model.WsShare, 0, batchSize) | ||||
| 	err = w.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 (w wsShareDo) FindInBatches(result *[]*model.WsShare, batchSize int, fc func(tx gen.Dao, batch int) error) error { | ||||
| 	return w.DO.FindInBatches(result, batchSize, fc) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Attrs(attrs ...field.AssignExpr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Attrs(attrs...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Assign(attrs ...field.AssignExpr) IWsShareDo { | ||||
| 	return w.withDO(w.DO.Assign(attrs...)) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Joins(fields ...field.RelationField) IWsShareDo { | ||||
| 	for _, _f := range fields { | ||||
| 		w = *w.withDO(w.DO.Joins(_f)) | ||||
| 	} | ||||
| 	return &w | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Preload(fields ...field.RelationField) IWsShareDo { | ||||
| 	for _, _f := range fields { | ||||
| 		w = *w.withDO(w.DO.Preload(_f)) | ||||
| 	} | ||||
| 	return &w | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) FirstOrInit() (*model.WsShare, error) { | ||||
| 	if result, err := w.DO.FirstOrInit(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.WsShare), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) FirstOrCreate() (*model.WsShare, error) { | ||||
| 	if result, err := w.DO.FirstOrCreate(); err != nil { | ||||
| 		return nil, err | ||||
| 	} else { | ||||
| 		return result.(*model.WsShare), nil | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) FindByPage(offset int, limit int) (result []*model.WsShare, count int64, err error) { | ||||
| 	result, err = w.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 = w.Offset(-1).Limit(-1).Count() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | ||||
| 	count, err = w.Count() | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err = w.Offset(offset).Limit(limit).Scan(result) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Scan(result interface{}) (err error) { | ||||
| 	return w.DO.Scan(result) | ||||
| } | ||||
|  | ||||
| func (w wsShareDo) Delete(models ...*model.WsShare) (result gen.ResultInfo, err error) { | ||||
| 	return w.DO.Delete(models) | ||||
| } | ||||
|  | ||||
| func (w *wsShareDo) withDO(do gen.Dao) *wsShareDo { | ||||
| 	w.DO = *do.(*gen.DO) | ||||
| 	return w | ||||
| } | ||||
| @@ -1,12 +1,9 @@ | ||||
| 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" | ||||
|  | ||||
| 	"gorm.io/gorm" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/repository/query" | ||||
| ) | ||||
|  | ||||
| type taskRepository struct{} | ||||
| @@ -40,33 +37,39 @@ func (t *taskRepository) DeleteTask(id int) (err error) { | ||||
| } | ||||
|  | ||||
| func (t *taskRepository) EditTask(data model.Task) (err error) { | ||||
| 	err = db.Model(&model.Task{}).Where(&model.Task{Id: data.Id}).First(&model.Task{}).Error | ||||
| 	if errors.Is(err, gorm.ErrRecordNotFound) { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = db.Model(&model.Task{}).Where(&model.Task{Id: data.Id}).Save(data).Error | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (t *taskRepository) EditTaskEnable(id int, enable bool) (err error) { | ||||
| 	err = db.Model(&model.Task{}).Where(&model.Task{Id: id}).First(&model.Task{}).Error | ||||
| 	if errors.Is(err, gorm.ErrRecordNotFound) { | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	err = db.Model(&model.Task{}).Where(&model.Task{Id: id}).Update("enable", enable).Error | ||||
| 	_, err = query.Task.Where(query.Task.Id.Eq(id)).Update(query.Task.Enable, enable) | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (t *taskRepository) GetAllTaskWithProcessName() (result []model.TaskVo) { | ||||
| 	db.Raw(`SELECT t.*, p.name AS process_name, p2.name AS target_name,p3.name AS trigger_name  | ||||
| 	FROM task t LEFT JOIN process p ON t.process_id = p.uuid LEFT JOIN process p2 ON t.operation_target = p2.uuid LEFT JOIN process p3 ON t.trigger_target = p3.uuid`).Scan(&result) | ||||
| 	p := query.Process.As("p") | ||||
| 	p2 := query.Process.As("p2") | ||||
| 	p3 := query.Process.As("p3") | ||||
| 	task := query.Task | ||||
| 	task.Select( | ||||
| 		task.ALL, | ||||
| 		p.Name.As("process_name"), | ||||
| 		p2.Name.As("target_name"), | ||||
| 		p3.Name.As("trigger_name"), | ||||
| 	). | ||||
| 		LeftJoin(p, p.Uuid.EqCol(task.ProcessId)). | ||||
| 		LeftJoin(p2, p2.Uuid.EqCol(task.OperationTarget)). | ||||
| 		LeftJoin(p3, p3.Uuid.EqCol(task.TriggerTarget)). | ||||
| 		Scan(&result) | ||||
| 	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{} | ||||
| 	db.Raw(`SELECT task.* FROM task left join process p  on p.uuid == task.trigger_target  WHERE trigger_event= ? AND p.name = ?`, event, processName).Scan(&result) | ||||
| 	query.Task.Select(query.Task.ALL). | ||||
| 		LeftJoin(query.Process, query.Process.Uuid.EqCol(query.Task.TriggerTarget)). | ||||
| 		Where(query.Process.Name.Eq(processName)). | ||||
| 		Where(query.Task.TriggerEvent.Eq(int32(event))). | ||||
| 		Scan(result) | ||||
| 	return result | ||||
| } | ||||
|   | ||||
| @@ -25,20 +25,14 @@ func (u *userRepository) CreateUser(user model.User) error { | ||||
| } | ||||
|  | ||||
| func (u *userRepository) UpdatePassword(name string, password string) error { | ||||
| 	tx := db.Model(&model.User{}).Where(&model.User{Account: name}).Updates(&model.User{Password: utils.Md5(password)}) | ||||
| 	return tx.Error | ||||
| 	return db.Model(&model.User{}).Where(&model.User{Account: name}).Updates(&model.User{Password: utils.Md5(password)}).Error | ||||
| } | ||||
|  | ||||
| func (u *userRepository) DeleteUser(name string) error { | ||||
| 	if err := db.Model(&model.User{}).Where(&model.User{Account: name}).First(&model.User{}).Error; err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	tx := db.Delete(&model.User{Account: name}) | ||||
| 	return tx.Error | ||||
| 	return db.Delete(&model.User{Account: name}).Error | ||||
| } | ||||
|  | ||||
| func (u *userRepository) GetUserList() []model.User { | ||||
| 	result := []model.User{} | ||||
| func (u *userRepository) GetUserList() (result []model.User) { | ||||
| 	db.Find(&result) | ||||
| 	return result | ||||
| 	return | ||||
| } | ||||
|   | ||||
							
								
								
									
										37
									
								
								internal/app/repository/ws_share.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								internal/app/repository/ws_share.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| 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 wsShare struct{} | ||||
|  | ||||
| var WsShare = new(wsShare) | ||||
|  | ||||
| func (p *wsShare) GetWsShareDataByToken(token string) (data *model.WsShare, err error) { | ||||
| 	data, err = query.WsShare.Where(query.WsShare.Token.Eq(token)).First() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *wsShare) AddShareData(data model.WsShare) error { | ||||
| 	return db.Save(&data).Error | ||||
| } | ||||
|  | ||||
| func (p *wsShare) GetWsShareList() (data []*model.WsShare) { | ||||
| 	ws := query.WsShare | ||||
| 	data, _ = ws.Order(ws.CreatedAt.Desc()).Find() | ||||
| 	return | ||||
| } | ||||
|  | ||||
| func (p *wsShare) Delete(id int) error { | ||||
| 	ws := query.WsShare | ||||
| 	_, err := ws.Where(ws.ID.Eq(uint(id))).Delete() | ||||
| 	return err | ||||
| } | ||||
|  | ||||
| func (p *wsShare) Edit(data *model.WsShare) error { | ||||
| 	ws := query.WsShare | ||||
| 	_, err := ws.Where(ws.ID.Eq(uint(data.ID))).Updates(data) | ||||
| 	return err | ||||
| } | ||||
| @@ -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" | ||||
| @@ -20,7 +20,7 @@ func Route() { | ||||
| 	r := gin.New() | ||||
| 	r.Use(gin.Recovery()) | ||||
| 	if !config.CF.Tui { | ||||
| 		r.Use(gin.Logger()) | ||||
| 		r.Use(middle.Logger()) | ||||
| 	} | ||||
| 	routePathInit(r) | ||||
| 	staticInit(r) | ||||
| @@ -51,89 +51,160 @@ func pprofInit(r *gin.Engine) { | ||||
| } | ||||
|  | ||||
| func routePathInit(r *gin.Engine) { | ||||
|  | ||||
| 	apiGroup := r.Group("/api") | ||||
| 	apiGroup.Use(middle.CheckToken()) | ||||
| 	apiGroup.Use(middle.PanicMiddle()) | ||||
| 	// apiGroup.Use(middle.DemoMiddle()) | ||||
| 	{ | ||||
| 		apiGroup.GET("/ws", middle.OprPermission(constants.OPERATION_TERMINAL), api.WsApi.WebsocketHandle) | ||||
| 		wsGroup := apiGroup.Group("/ws") | ||||
| 		{ | ||||
| 			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), api.ProcApi.KillProcess) | ||||
| 			processGroup.GET("", api.ProcApi.GetProcessList) | ||||
| 			processGroup.GET("/wait", middle.ProcessWaitCond.WaitGetMiddel, api.ProcApi.GetProcessList) | ||||
| 			processGroup.PUT("", middle.OprPermission(constants.OPERATION_START), api.ProcApi.StartProcess) | ||||
| 			processGroup.PUT("/all", api.ProcApi.StartAllProcess) | ||||
| 			processGroup.DELETE("/all", api.ProcApi.KillAllProcess) | ||||
| 			processGroup.GET("/control", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, api.ProcApi.ProcessControl) | ||||
| 			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(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(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, api.ProcApi.CreateNewProcess) | ||||
| 				proConfigGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), middle.ProcessWaitCond.WaitTriggerMiddel, api.ProcApi.DeleteNewProcess) | ||||
| 				proConfigGroup.PUT("", middle.RolePermission(constants.ROLE_ROOT), api.ProcApi.UpdateProcessConfig) | ||||
| 				proConfigGroup.GET("", middle.RolePermission(constants.ROLE_ADMIN), api.ProcApi.GetProcessConfig) | ||||
| 				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), api.TaskApi.GetTaskById) | ||||
| 			taskGroup.GET("/all", middle.RolePermission(constants.ROLE_ADMIN), api.TaskApi.GetTaskList) | ||||
| 			taskGroup.GET("/all/wait", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitGetMiddel, api.TaskApi.GetTaskList) | ||||
| 			taskGroup.POST("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, api.TaskApi.CreateTask) | ||||
| 			taskGroup.DELETE("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, api.TaskApi.DeleteTaskById) | ||||
| 			taskGroup.PUT("", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, api.TaskApi.EditTask) | ||||
| 			taskGroup.PUT("/enable", middle.RolePermission(constants.ROLE_ADMIN), middle.TaskWaitCond.WaitTriggerMiddel, api.TaskApi.EditTaskEnable) | ||||
| 			taskGroup.GET("/start", middle.RolePermission(constants.ROLE_ADMIN), api.TaskApi.StartTask) | ||||
| 			taskGroup.GET("/stop", middle.RolePermission(constants.ROLE_ADMIN), api.TaskApi.StopTask) | ||||
| 			taskGroup.POST("/key", middle.RolePermission(constants.ROLE_ADMIN), api.TaskApi.CreateTaskApiKey) | ||||
| 			taskGroup.GET("/api-key/:key", api.TaskApi.RunTaskByKey) | ||||
| 			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", api.UserApi.LoginHandler) | ||||
| 			userGroup.POST("", middle.RolePermission(constants.ROLE_ROOT), api.UserApi.CreateUser) | ||||
| 			userGroup.PUT("/password", middle.RolePermission(constants.ROLE_USER), api.UserApi.ChangePassword) | ||||
| 			userGroup.DELETE("", middle.RolePermission(constants.ROLE_ROOT), api.UserApi.DeleteUser) | ||||
| 			userGroup.GET("", middle.RolePermission(constants.ROLE_ROOT), api.UserApi.GetUserList) | ||||
| 			userGroup.POST("/login", bind(api.UserApi.LoginHandler, Body)) | ||||
| 			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", api.PushApi.GetPushList) | ||||
| 			pushGroup.GET("", api.PushApi.GetPushById) | ||||
| 			pushGroup.POST("", api.PushApi.AddPushConfig) | ||||
| 			pushGroup.PUT("", api.PushApi.UpdatePushConfig) | ||||
| 			pushGroup.DELETE("", api.PushApi.DeletePushConfig) | ||||
| 			pushGroup.GET("/list", bind(api.PushApi.GetPushList, None)) | ||||
| 			pushGroup.GET("", bind(api.PushApi.GetPushById, Query)) | ||||
| 			pushGroup.POST("", bind(api.PushApi.AddPushConfig, Body)) | ||||
| 			pushGroup.PUT("", bind(api.PushApi.UpdatePushConfig, Body)) | ||||
| 			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", api.FileApi.FilePathHandler) | ||||
| 			fileGroup.PUT("", api.FileApi.FileWriteHandler) | ||||
| 			fileGroup.GET("", api.FileApi.FileReadHandler) | ||||
| 			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", api.PermissionApi.GetPermissionList) | ||||
| 			permissionGroup.PUT("", middle.ProcessWaitCond.WaitTriggerMiddel, api.PermissionApi.EditPermssion) | ||||
| 			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("", api.LogApi.GetLog) | ||||
| 			logGroup.GET("/running", api.LogApi.GetRunningLog) | ||||
| 			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("", api.ConfigApi.GetSystemConfiguration) | ||||
| 			configGroup.PUT("", api.ConfigApi.SetSystemConfiguration) | ||||
| 			configGroup.PUT("/es", api.ConfigApi.EsConfigReload) | ||||
| 			configGroup.GET("", bind(api.ConfigApi.GetSystemConfiguration, None)) | ||||
| 			configGroup.PUT("", bind(api.ConfigApi.SetSystemConfiguration, None)) | ||||
| 			configGroup.GET("/reload", bind(api.ConfigApi.LogConfigReload, None)) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| const ( | ||||
| 	None   = 0 | ||||
| 	Header = 1 << iota | ||||
| 	Body | ||||
| 	Query | ||||
| ) | ||||
|  | ||||
| func bind[T any, R any](fn func(*gin.Context, T) R, bindOption int) func(*gin.Context) { | ||||
| 	return func(ctx *gin.Context) { | ||||
| 		var req T | ||||
| 		if bindOption&Body != 0 { | ||||
| 			if err := ctx.BindJSON(&req); err != nil { | ||||
| 				rErr(ctx, err) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		if bindOption&Header != 0 { | ||||
| 			if err := ctx.BindHeader(&req); err != nil { | ||||
| 				rErr(ctx, err) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		if bindOption&Query != 0 { | ||||
| 			if err := ctx.BindQuery(&req); err != nil { | ||||
| 				rErr(ctx, err) | ||||
| 				return | ||||
| 			} | ||||
| 		} | ||||
| 		result := fn(ctx, req) | ||||
| 		switch v := any(result).(type) { | ||||
| 		case error: | ||||
| 			if v != nil { | ||||
| 				rErr(ctx, v) | ||||
| 				return | ||||
| 			} else { | ||||
| 				ctx.JSON(200, gin.H{ | ||||
| 					"code":    0, | ||||
| 					"message": "success", | ||||
| 				}) | ||||
| 				return | ||||
| 			} | ||||
| 		case *api.Response: | ||||
| 			ctx.JSON(v.StatusCode, gin.H{ | ||||
| 				"data": v.Data, | ||||
| 				"msg":  v.Msg, | ||||
| 				"code": v.Code, | ||||
| 			}) | ||||
| 			return | ||||
| 		default: | ||||
| 			ctx.JSON(200, gin.H{ | ||||
| 				"code":    0, | ||||
| 				"message": "success", | ||||
| 				"data":    v, | ||||
| 			}) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func rErr(ctx *gin.Context, err error) { | ||||
| 	log.Logger.Warn(err) | ||||
| 	ctx.JSON(500, gin.H{ | ||||
| 		"code":    -1, | ||||
| 		"message": err.Error(), | ||||
| 	}) | ||||
| } | ||||
|   | ||||
							
								
								
									
										167
									
								
								internal/app/search/bleve/bleve.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								internal/app/search/bleve/bleve.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| //go:build !slim | ||||
| // +build !slim | ||||
|  | ||||
| package bleve | ||||
|  | ||||
| import ( | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/blevesearch/bleve/v2" | ||||
| 	"github.com/blevesearch/bleve/v2/search" | ||||
| 	_ "github.com/blevesearch/bleve/v2/search/highlight/highlighter/ansi" | ||||
| 	"github.com/google/uuid" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	sr "github.com/lzh-1625/go_process_manager/internal/app/search" | ||||
| 	logger "github.com/lzh-1625/go_process_manager/log" | ||||
| 	gse "github.com/vcaesar/gse-bleve" | ||||
| 	// gse "github.com/lzh-1625/gse-bleve" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	sr.Register("bleve", new(bleveSearch)) | ||||
| } | ||||
|  | ||||
| type bleveSearch struct { | ||||
| 	index bleve.Index | ||||
| } | ||||
|  | ||||
| func (b *bleveSearch) Init() error { | ||||
| 	opt := gse.Option{ | ||||
| 		Dicts: "embed, zh_s", | ||||
| 		Stop:  "", | ||||
| 		Opt:   "search-hmm", | ||||
| 		Trim:  "trim", | ||||
| 	} | ||||
| 	indexMapping, err := gse.NewMapping(opt) | ||||
| 	if err != nil { | ||||
| 		logger.Logger.Errorw("bleve init fail", "err", err) | ||||
| 		return err | ||||
| 	} | ||||
| 	mapping := bleve.NewDocumentMapping() | ||||
| 	log := bleve.NewTextFieldMapping() | ||||
| 	log.Index = true | ||||
| 	time := bleve.NewNumericFieldMapping() | ||||
| 	time.Index = true | ||||
| 	name := bleve.NewKeywordFieldMapping() | ||||
| 	name.Index = true | ||||
| 	using := bleve.NewKeywordFieldMapping() | ||||
| 	using.Index = true | ||||
| 	mapping.AddFieldMappingsAt("log", log) | ||||
| 	mapping.AddFieldMappingsAt("time", time) | ||||
| 	mapping.AddFieldMappingsAt("name", name) | ||||
| 	mapping.AddFieldMappingsAt("using", using) | ||||
| 	indexMapping.AddDocumentMapping("server_log_v1", mapping) | ||||
| 	index, err := bleve.Open("log.bleve") | ||||
| 	if err != nil { | ||||
| 		index, err = bleve.New("log.bleve", indexMapping) | ||||
| 		if err != nil { | ||||
| 			logger.Logger.Errorw("bleve init error", "err", err) | ||||
| 			return err | ||||
| 		} | ||||
| 	} | ||||
| 	b.index = index | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (b *bleveSearch) Insert(logContent string, processName string, using string, ts int64) { | ||||
| 	if err := b.index.Index(uuid.NewString(), model.ProcessLog{ | ||||
| 		Log:   logContent, | ||||
| 		Name:  processName, | ||||
| 		Using: using, | ||||
| 		Time:  ts, | ||||
| 	}); err != nil { | ||||
| 		logger.Logger.Warnw("bleve log insert failed", "err", err) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (b *bleveSearch) Search(req model.GetLogReq, filterProcessName ...string) (result model.LogResp) { | ||||
| 	buildQuery := bleve.NewBooleanQuery() | ||||
| 	for _, v := range sr.QueryStringAnalysis(req.Match.Log) { | ||||
| 		switch v.Cond { | ||||
| 		case sr.Match, sr.WildCard: | ||||
| 			logQuery := bleve.NewMatchQuery(v.Content) | ||||
| 			logQuery.SetField("log") | ||||
| 			buildQuery.AddMust(logQuery) | ||||
| 		case sr.NotMatch, sr.NotWildCard: | ||||
| 			logQuery := bleve.NewMatchQuery(v.Content) | ||||
| 			logQuery.SetField("log") | ||||
| 			buildQuery.AddMustNot(logQuery) | ||||
| 			// case sr.WildCard: | ||||
| 			// 	logQuery := bleve.NewWildcardQuery("*" + v.Content + "*") | ||||
| 			// 	logQuery.SetField("log") | ||||
| 			// 	buildQuery.AddMust(logQuery) | ||||
| 			// case sr.NotWildCard: | ||||
| 			// 	logQuery := bleve.NewWildcardQuery("*" + v.Content + "*") | ||||
| 			// 	logQuery.SetField("log") | ||||
| 			// 	buildQuery.AddMustNot(logQuery) | ||||
| 		} | ||||
| 	} | ||||
| 	if req.Match.Name != "" { | ||||
| 		nameQuery := bleve.NewTermQuery(req.Match.Name) | ||||
| 		nameQuery.SetField("name") | ||||
| 		buildQuery.AddMust(nameQuery) | ||||
| 	} | ||||
| 	if req.Match.Using != "" { | ||||
| 		usingQuery := bleve.NewWildcardQuery("*" + req.Match.Using + "*") | ||||
| 		usingQuery.SetField("using") | ||||
| 		buildQuery.AddMust(usingQuery) | ||||
| 	} | ||||
| 	if req.TimeRange.EndTime != 0 || req.TimeRange.StartTime != 0 { | ||||
| 		st := float64(req.TimeRange.StartTime) | ||||
| 		et := float64(req.TimeRange.EndTime) | ||||
| 		timeQuery := bleve.NewNumericRangeQuery(&st, &et) | ||||
| 		buildQuery.AddMust(timeQuery) | ||||
| 	} else { | ||||
| 		st := float64(0) | ||||
| 		et := float64(time.Now().UnixMilli()) | ||||
| 		timeQuery := bleve.NewNumericRangeQuery(&st, &et) | ||||
| 		buildQuery.AddMust(timeQuery) | ||||
| 	} | ||||
| 	if len(filterProcessName) != 0 { | ||||
| 		for _, v := range filterProcessName { | ||||
| 			filterQuery := bleve.NewTermQuery(v) | ||||
| 			filterQuery.SetField("name") | ||||
| 			buildQuery.AddShould(filterQuery) | ||||
| 		} | ||||
| 	} | ||||
| 	sortArgs := ([]string{"-_score"}) | ||||
| 	if req.Sort == "desc" { | ||||
|  | ||||
| 		sortArgs = ([]string{"-time"}) | ||||
| 	} | ||||
| 	if req.Sort == "asc" { | ||||
| 		sortArgs = ([]string{"time"}) | ||||
| 	} | ||||
| 	hl := bleve.HighlightRequest{} | ||||
| 	hl.AddField("log") | ||||
| 	style := "ansi" | ||||
| 	res, err := b.index.Search(&bleve.SearchRequest{ | ||||
| 		Query:  buildQuery, | ||||
| 		Fields: []string{"log", "name", "using", "time"}, | ||||
| 		From:   req.Page.From, | ||||
| 		Size:   req.Page.Size, | ||||
| 		Sort:   search.ParseSortOrderStrings(sortArgs), | ||||
| 		Highlight: &bleve.HighlightRequest{ | ||||
| 			Style:  &style, | ||||
| 			Fields: []string{"log"}, | ||||
| 		}, | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		logger.Logger.Warnw("bleve search failed", "err", err) | ||||
| 		return | ||||
| 	} | ||||
| 	data := []*model.ProcessLog{} | ||||
| 	for _, v := range res.Hits { | ||||
| 		data = append(data, &model.ProcessLog{ | ||||
| 			Log:   v.Fragments["log"][0], | ||||
| 			Time:  int64(v.Fields["time"].(float64)), | ||||
| 			Using: v.Fields["using"].(string), | ||||
| 			Name:  v.Fields["name"].(string), | ||||
| 		}) | ||||
| 	} | ||||
|  | ||||
| 	result.Data = data | ||||
| 	result.Total = int64(res.Total) | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										4
									
								
								internal/app/search/bleve/bleve_ignore.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								internal/app/search/bleve/bleve_ignore.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| //go:build slim | ||||
| // +build slim | ||||
|  | ||||
| package bleve | ||||
| @@ -1,36 +1,31 @@ | ||||
| package logic | ||||
| package es | ||||
| 
 | ||||
| import ( | ||||
| 	"context" | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
| 	"reflect" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	sr "github.com/lzh-1625/go_process_manager/internal/app/search" | ||||
| 	"github.com/lzh-1625/go_process_manager/log" | ||||
| 
 | ||||
| 	"github.com/olivere/elastic/v7" | ||||
| ) | ||||
| 
 | ||||
| type esLogic struct { | ||||
| func init() { | ||||
| 	sr.Register("es", new(esSearch)) | ||||
| } | ||||
| 
 | ||||
| type esSearch struct { | ||||
| 	esClient *elastic.Client | ||||
| } | ||||
| 
 | ||||
| var ( | ||||
| 	EsLogic = new(esLogic) | ||||
| ) | ||||
| 
 | ||||
| func (e *esLogic) InitEs() bool { | ||||
| 	if !config.CF.EsEnable { | ||||
| 		log.Logger.Debug("不使用es") | ||||
| 		return false | ||||
| 	} | ||||
| 
 | ||||
| func (e *esSearch) Init() error { | ||||
| 	var err error | ||||
| 	EsLogic.esClient, err = elastic.NewClient( | ||||
| 	e.esClient, err = elastic.NewClient( | ||||
| 		elastic.SetURL(config.CF.EsUrl), | ||||
| 		elastic.SetBasicAuth(config.CF.EsUsername, config.CF.EsPassword), | ||||
| 		elastic.SetSniff(false), | ||||
| @@ -42,15 +37,13 @@ func (e *esLogic) InitEs() bool { | ||||
| 		}), | ||||
| 	) | ||||
| 	if err != nil { | ||||
| 		config.CF.EsEnable = false | ||||
| 		log.Logger.Warnw("Failed to connect to es", "err", err) | ||||
| 		return false | ||||
| 		return err | ||||
| 	} | ||||
| 	EsLogic.CreateIndexIfNotExists(config.CF.EsIndex) | ||||
| 	return true | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (e *esLogic) Insert(logContent string, processName string, using string, ts int64) { | ||||
| func (e *esSearch) Insert(logContent string, processName string, using string, ts int64) { | ||||
| 	data := model.ProcessLog{ | ||||
| 		Log:   logContent, | ||||
| 		Name:  processName, | ||||
| @@ -63,32 +56,11 @@ func (e *esLogic) Insert(logContent string, processName string, using string, ts | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (e *esLogic) CreateIndexIfNotExists(index string) error { | ||||
| 
 | ||||
| 	ctx := context.Background() | ||||
| 	exists, err := e.esClient.IndexExists(index).Do(ctx) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if exists { | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	info, err := e.esClient.CreateIndex(index).BodyString(e.structToJSON()).Do(ctx) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	if !info.Acknowledged { | ||||
| 		return fmt.Errorf("ES 创建索引 [%s] 失败", index) | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp { | ||||
| func (e *esSearch) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp { | ||||
| 	// 检查 req 是否为 nil | ||||
| 	if req.Page.From < 0 || req.Page.Size <= 0 { | ||||
| 		log.Logger.Error("无效的分页请求参数") | ||||
| 		return model.LogResp{Total: 0, Data: []model.ProcessLog{}} | ||||
| 		return model.LogResp{Total: 0, Data: []*model.ProcessLog{}} | ||||
| 	} | ||||
| 
 | ||||
| 	search := e.esClient.Search(config.CF.EsIndex).From(req.Page.From).Size(req.Page.Size).TrackScores(true) | ||||
| @@ -107,16 +79,29 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model | ||||
| 	if req.TimeRange.EndTime != 0 { | ||||
| 		queryList = append(queryList, timeRangeQuery.Lte(req.TimeRange.EndTime)) | ||||
| 	} | ||||
| 	if req.Match.Log != "" { | ||||
| 		queryList = append(queryList, elastic.NewMatchQuery("log", req.Match.Log)) | ||||
| 	notQuery := []elastic.Query{} | ||||
| 
 | ||||
| 	for _, v := range sr.QueryStringAnalysis(req.Match.Log) { | ||||
| 		switch v.Cond { | ||||
| 		case sr.Match: | ||||
| 			queryList = append(queryList, elastic.NewMatchQuery("log", v.Content)) | ||||
| 		case sr.NotMatch: | ||||
| 			notQuery = append(notQuery, elastic.NewMatchQuery("log", v.Content)) | ||||
| 		case sr.WildCard: | ||||
| 			queryList = append(queryList, elastic.NewWildcardQuery("log.keyword", "*"+v.Content+"*")) | ||||
| 		case sr.NotWildCard: | ||||
| 			notQuery = append(notQuery, elastic.NewWildcardQuery("log.keyword", "*"+v.Content+"*")) | ||||
| 		} | ||||
| 		fmt.Printf("v.Cond: %v\n", v.Cond) | ||||
| 		fmt.Printf("v.Content: %v\n", v.Content) | ||||
| 	} | ||||
| 
 | ||||
| 	if req.Match.Name != "" { | ||||
| 		queryList = append(queryList, elastic.NewMatchQuery("name", req.Match.Name)) | ||||
| 	} | ||||
| 	if req.Match.Using != "" { | ||||
| 		queryList = append(queryList, elastic.NewMatchQuery("using", req.Match.Using)) | ||||
| 	} | ||||
| 
 | ||||
| 	if len(filterProcessName) != 0 { // 过滤进程名 | ||||
| 		shouldQueryList := []elastic.Query{} | ||||
| 		for _, fpn := range filterProcessName { | ||||
| @@ -129,7 +114,7 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model | ||||
| 	} | ||||
| 
 | ||||
| 	result := model.LogResp{} | ||||
| 	resp, err := search.Query(elastic.NewBoolQuery().Must(queryList...)).Do(context.TODO()) | ||||
| 	resp, err := search.Query(elastic.NewBoolQuery().Must(queryList...).MustNot(notQuery...)).Highlight(elastic.NewHighlight().Field("log").PreTags("\033[43m").PostTags("\033[0m")).Do(context.TODO()) | ||||
| 	if err != nil { | ||||
| 		log.Logger.Errorw("es查询失败", "err", err, "reason", resp.Error.Reason) | ||||
| 		return result | ||||
| @@ -140,7 +125,10 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model | ||||
| 		if v.Source != nil { | ||||
| 			var data model.ProcessLog | ||||
| 			if err := json.Unmarshal(v.Source, &data); err == nil { | ||||
| 				result.Data = append(result.Data, data) | ||||
| 				if len(v.Highlight) > 0 && len(v.Highlight["log"]) > 0 { | ||||
| 					data.Log = v.Highlight["log"][0] | ||||
| 				} | ||||
| 				result.Data = append(result.Data, &data) | ||||
| 			} else { | ||||
| 				log.Logger.Errorw("JSON 解码失败", "err", err) | ||||
| 			} | ||||
| @@ -150,28 +138,3 @@ func (e *esLogic) Search(req model.GetLogReq, filterProcessName ...string) model | ||||
| 	result.Total = resp.TotalHits() | ||||
| 	return result | ||||
| } | ||||
| 
 | ||||
| // 通过反射得到mapping | ||||
| func (e *esLogic) structToJSON() string { | ||||
| 	typ := reflect.TypeOf(model.ProcessLog{}) | ||||
| 	properties := make(map[string]map[string]string) | ||||
| 	for i := 0; i < typ.NumField(); i++ { | ||||
| 		field := typ.Field(i) | ||||
| 		fieldTag := field.Tag.Get("type") | ||||
| 		if fieldTag != "" { | ||||
| 			properties[field.Tag.Get("json")] = map[string]string{ | ||||
| 				"type": fieldTag, | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	result := map[string]interface{}{ | ||||
| 		"mappings": map[string]interface{}{ | ||||
| 			"properties": properties, | ||||
| 		}, | ||||
| 	} | ||||
| 	jsonData, err := json.Marshal(result) | ||||
| 	if err != nil { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return string(jsonData) | ||||
| } | ||||
							
								
								
									
										69
									
								
								internal/app/search/search.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								internal/app/search/search.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| package search | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/internal/app/model" | ||||
| 	"github.com/lzh-1625/go_process_manager/log" | ||||
| ) | ||||
|  | ||||
| type LogLogic interface { | ||||
| 	Search(req model.GetLogReq, filterProcessName ...string) model.LogResp | ||||
| 	Insert(log string, processName string, using string, ts int64) | ||||
| 	Init() error | ||||
| } | ||||
|  | ||||
| var searchImplMap map[string]LogLogic = map[string]LogLogic{} | ||||
|  | ||||
| func Register(name string, impl LogLogic) { | ||||
| 	searchImplMap[name] = impl | ||||
| } | ||||
|  | ||||
| func GetSearchImpl(name string) LogLogic { | ||||
| 	v, ok := searchImplMap[name] | ||||
| 	if ok { | ||||
| 		return v | ||||
| 	} | ||||
| 	log.Logger.Warnw("未找到对应的存储引擎,使用默认[sqlite]", "name", name) | ||||
| 	return searchImplMap["sqlite"] | ||||
| } | ||||
|  | ||||
| type Cond int | ||||
|  | ||||
| const ( | ||||
| 	Match       Cond = iota // ^ | ||||
| 	WildCard                // ~ | ||||
| 	NotMatch                // !^ | ||||
| 	NotWildCard             // !~ | ||||
| ) | ||||
|  | ||||
| type Query struct { | ||||
| 	Cond    Cond | ||||
| 	Content string | ||||
| } | ||||
|  | ||||
| func QueryStringAnalysis(s string) (query []Query) { | ||||
| 	if strings.TrimSpace(s) == "" { | ||||
| 		return | ||||
| 	} | ||||
| 	strList := strings.Split(s, " ") | ||||
| 	for _, v := range strList { | ||||
| 		switch { | ||||
| 		case strings.HasPrefix(v, "!^"): | ||||
| 			query = append(query, Query{NotMatch, v[2:]}) | ||||
| 		case strings.HasPrefix(v, "!~"): | ||||
| 			query = append(query, Query{NotWildCard, v[2:]}) | ||||
| 		case strings.HasPrefix(v, "!"): | ||||
| 			query = append(query, Query{NotMatch, v[1:]}) | ||||
| 		case strings.HasPrefix(v, "^"): | ||||
| 			query = append(query, Query{Match, v[1:]}) | ||||
| 		case strings.HasPrefix(v, "~"): | ||||
| 			query = append(query, Query{WildCard, v[1:]}) | ||||
| 		default: | ||||
| 			query = append(query, Query{Match, v}) | ||||
| 		} | ||||
| 	} | ||||
| 	fmt.Printf("query: %v\n", query) | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										47
									
								
								internal/app/search/sqlite/sqlite.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								internal/app/search/sqlite/sqlite.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| package sqlite | ||||
|  | ||||
| import ( | ||||
| 	"slices" | ||||
| 	"strings" | ||||
|  | ||||
| 	"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/search" | ||||
| ) | ||||
|  | ||||
| func init() { | ||||
| 	search.Register("sqlite", new(sqliteSearch)) | ||||
| } | ||||
|  | ||||
| type sqliteSearch struct{} | ||||
|  | ||||
| func (l *sqliteSearch) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp { | ||||
| 	req.FilterName = filterProcessName | ||||
| 	query := search.QueryStringAnalysis(req.Match.Log) | ||||
| 	data, total := repository.LogRepository.SearchLog(req, query) | ||||
| 	for _, v := range slices.DeleteFunc(query, func(q search.Query) bool { | ||||
| 		return q.Cond == search.NotMatch || q.Cond == search.NotWildCard | ||||
| 	}) { | ||||
| 		for i := range data { | ||||
| 			data[i].Log = strings.ReplaceAll(data[i].Log, v.Content, "\033[43m"+v.Content+"\033[0m") | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return model.LogResp{ | ||||
| 		Data:  data, | ||||
| 		Total: total, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (l *sqliteSearch) Insert(log string, processName string, using string, ts int64) { | ||||
| 	repository.LogRepository.InsertLog(model.ProcessLog{ | ||||
| 		Log:   log, | ||||
| 		Name:  processName, | ||||
| 		Using: using, | ||||
| 		Time:  ts, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func (l *sqliteSearch) Init() error { | ||||
| 	return nil | ||||
| } | ||||
| @@ -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() | ||||
|   | ||||
							
								
								
									
										51
									
								
								log/log.go
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								log/log.go
									
									
									
									
									
								
							| @@ -5,57 +5,13 @@ import ( | ||||
|  | ||||
| 	"github.com/lzh-1625/go_process_manager/config" | ||||
|  | ||||
| 	"github.com/timandy/routine" | ||||
| 	"go.uber.org/zap" | ||||
| 	"go.uber.org/zap/zapcore" | ||||
| ) | ||||
|  | ||||
| var Logger *logWithAdditional | ||||
|  | ||||
| type logWithAdditional struct { | ||||
| 	*zap.SugaredLogger | ||||
| 	threadLocal routine.ThreadLocal[[]any] | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) Infow(msg string, keysAndValues ...interface{}) { | ||||
| 	keysAndValues = append(keysAndValues, l.threadLocal.Get()...) | ||||
| 	l.SugaredLogger.WithOptions(zap.AddCallerSkip(1)).Infow(msg, keysAndValues...) | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) Debugw(msg string, keysAndValues ...interface{}) { | ||||
| 	keysAndValues = append(keysAndValues, l.threadLocal.Get()...) | ||||
| 	l.SugaredLogger.WithOptions(zap.AddCallerSkip(1)).Debugw(msg, keysAndValues...) | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) Errorw(msg string, keysAndValues ...interface{}) { | ||||
| 	keysAndValues = append(keysAndValues, l.threadLocal.Get()...) | ||||
| 	l.SugaredLogger.WithOptions(zap.AddCallerSkip(1)).Errorw(msg, keysAndValues...) | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) Warnw(msg string, keysAndValues ...interface{}) { | ||||
| 	keysAndValues = append(keysAndValues, l.threadLocal.Get()...) | ||||
| 	l.SugaredLogger.WithOptions(zap.AddCallerSkip(1)).Warnw(msg, keysAndValues...) | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) AddAdditionalInfo(k, v any) { | ||||
| 	l.threadLocal.Set(append(l.threadLocal.Get(), k, v)) | ||||
| } | ||||
|  | ||||
| func (l *logWithAdditional) DeleteAdditionalInfo(layer int) { | ||||
| 	if layer < 0 { | ||||
| 		l.threadLocal.Set([]any{}) | ||||
| 		return | ||||
| 	} | ||||
| 	oldKv := l.threadLocal.Get() | ||||
| 	if len(oldKv) < layer*2 { | ||||
| 		l.threadLocal.Set([]any{}) | ||||
| 		return | ||||
| 	} | ||||
| 	l.threadLocal.Set(oldKv[:len(oldKv)-2*layer]) | ||||
| } | ||||
| var Logger *zap.SugaredLogger | ||||
|  | ||||
| func InitLog() { | ||||
|  | ||||
| 	encoderConfig := zapcore.EncoderConfig{ | ||||
| 		TimeKey:        "time", | ||||
| 		LevelKey:       "level", | ||||
| @@ -89,8 +45,5 @@ func InitLog() { | ||||
| 		ErrorOutputPaths: []string{"stderr"}, | ||||
| 	} | ||||
| 	log, _ := config.Build() | ||||
| 	Logger = &logWithAdditional{ | ||||
| 		SugaredLogger: log.Sugar(), | ||||
| 		threadLocal:   routine.NewThreadLocal[[]any](), | ||||
| 	} | ||||
| 	Logger = log.Sugar() | ||||
| } | ||||
|   | ||||
							
								
								
									
										4
									
								
								resources/.browserslistrc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								resources/.browserslistrc
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| > 1% | ||||
| last 2 versions | ||||
| not dead | ||||
| not ie 11 | ||||
							
								
								
									
										2
									
								
								resources/.dockerignore
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								resources/.dockerignore
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| node_modules | ||||
| npm-debug.log | ||||
							
								
								
									
										5
									
								
								resources/.editorconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								resources/.editorconfig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| [*.{js,jsx,ts,tsx,vue}] | ||||
| indent_style = space | ||||
| indent_size = 2 | ||||
| trim_trailing_whitespace = true | ||||
| insert_final_newline = true | ||||
							
								
								
									
										10
									
								
								resources/.env.dev
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								resources/.env.dev
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
|  | ||||
|  | ||||
| # Firebase 🔥 | ||||
| VITE_FIREBASE_API_KEY= | ||||
| VITE_FIREBASE_AUTH_DOMAIN= | ||||
| VITE_FIREBASE_PROJECT_ID= | ||||
| VITE_FIREBASE_STORAGE_BUCKET= | ||||
| VITE_FIREBASE_MESSAGING_SENDER_ID= | ||||
| VITE_FIREBASE_APP_ID= | ||||
| VITE_FIREBASE_MEASUREMENT_ID= | ||||
							
								
								
									
										1
									
								
								resources/.env.pro
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								resources/.env.pro
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| VITE_API_BASE_URL=https://api.example.com | ||||
							
								
								
									
										7
									
								
								resources/.env.template
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								resources/.env.template
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| VITE_OPENAI_API_KEY = XXXXXXXXXXXX | ||||
| VITE_UNSPLASH_ACCESS_KEY = XXXXXXXXXXXX | ||||
| VITE_GITHUB_CLIENT_ID = XXXXXXXXXXXX | ||||
| # Aruze TextToSpeech Key (required for tts) | ||||
| VITE_TTS_KEY=XXXXXXXXXXXX | ||||
| # Aruze TextToSpeech Region | ||||
| VITE_TTS_REGION = XXXXXXXXXXXX | ||||
							
								
								
									
										2
									
								
								resources/.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								resources/.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| # Auto detect text files and perform LF normalization | ||||
| * text=auto | ||||
							
								
								
									
										32
									
								
								resources/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								resources/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| .DS_Store | ||||
| node_modules | ||||
| /dist | ||||
| /.vite_cache | ||||
|  | ||||
|  | ||||
| # local env files | ||||
| .env | ||||
| .env.local | ||||
| .env.*.local | ||||
|  | ||||
| # Log files | ||||
| npm-debug.log* | ||||
| yarn-debug.log* | ||||
| yarn-error.log* | ||||
| pnpm-debug.log* | ||||
|  | ||||
| # Editor directories and files | ||||
| .idea | ||||
| .vscode | ||||
| *.suo | ||||
| *.ntvs* | ||||
| *.njsproj | ||||
| *.sln | ||||
| *.sw? | ||||
|  | ||||
| # Local Netlify folder | ||||
| .netlify | ||||
| .env | ||||
|  | ||||
| # yarn.lock | ||||
| yarn.lock | ||||
							
								
								
									
										3
									
								
								resources/.vite/deps_temp_61bc278e/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								resources/.vite/deps_temp_61bc278e/package.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| { | ||||
|   "type": "module" | ||||
| } | ||||
							
								
								
									
										13
									
								
								resources/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								resources/Dockerfile
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| # 构建阶段 | ||||
| FROM node:lts-alpine as build-stage | ||||
| WORKDIR /app | ||||
| COPY package*.json ./ | ||||
| RUN npm install | ||||
| COPY . . | ||||
| RUN npm run build | ||||
|  | ||||
| # 生产阶段 | ||||
| FROM nginx:stable-alpine as production-stage | ||||
| COPY --from=build-stage /app/dist /usr/share/nginx/html | ||||
| EXPOSE 80 | ||||
| CMD ["nginx", "-g", "daemon off;"] | ||||
							
								
								
									
										6
									
								
								resources/Dockerfile.dev
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								resources/Dockerfile.dev
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| FROM node:lts-alpine | ||||
| WORKDIR /app | ||||
| COPY package*.json ./ | ||||
| RUN npm install | ||||
| EXPOSE 8080 | ||||
| CMD ["npm", "run", "dev"] | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user