mirror of
				https://github.com/lzh-1625/go_process_manager.git
				synced 2025-10-31 11:26:49 +08:00 
			
		
		
		
	optimal storge choice
This commit is contained in:
		| @@ -1,72 +1,17 @@ | ||||
| package logic | ||||
|  | ||||
| import ( | ||||
| 	"strings" | ||||
|  | ||||
| 	"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/log" | ||||
| 	"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() { | ||||
| 	switch config.CF.StorgeType { | ||||
| 	case "es": | ||||
| 		LogLogicImpl = LogEs | ||||
| 		EsLogic.InitEs() | ||||
| 		log.Logger.Infow("使用es作为日志存储") | ||||
| 	case "bleve": | ||||
| 		LogLogicImpl = BleveLogic | ||||
| 		BleveLogic.InitBleve() | ||||
| 		log.Logger.Infow("使用bleve作为日志存储") | ||||
| 	default: | ||||
| 		LogLogicImpl = LogSqlite | ||||
| 		log.Logger.Infow("使用sqlite作为日志存储") | ||||
| 	} | ||||
| } | ||||
|  | ||||
| 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) | ||||
| 	if req.Match.Log != "" { | ||||
| 		for i := range data { | ||||
| 			data[i].Log = strings.ReplaceAll(data[i].Log, req.Match.Log, "\033[43m"+req.Match.Log+"\033[0m") | ||||
| 		} | ||||
| 	} | ||||
| 	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() | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 lzh
					lzh