2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package router
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								import (
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-09 18:26:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"mayfly-go/internal/mongo/api"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"mayfly-go/internal/mongo/application"
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-26 20:49:29 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									tagapp "mayfly-go/internal/tag/application"
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									"mayfly-go/pkg/req"
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									"github.com/gin-gonic/gin"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func InitMongoRouter(router *gin.RouterGroup) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									m := router.Group("mongos")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										ma := &api.Mongo{
							 | 
						
					
						
							
								
									
										
										
										
											2022-09-09 18:26:08 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											MongoApp: application.GetMongoApp(),
							 | 
						
					
						
							
								
									
										
										
										
											2022-10-26 20:49:29 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											TagApp:   tagapp.GetTagTreeApp(),
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 获取所有mongo列表
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.GET("", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.Mongos)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										saveMongo := req.NewLogInfo("mongo-保存信息")
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST("", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WithLog(saveMongo).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.Save)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										deleteMongo := req.NewLogInfo("mongo-删除信息")
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.DELETE(":id", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WithLog(deleteMongo).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.DeleteMongo)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 获取mongo下的所有数据库
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.GET(":id/databases", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.Databases)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 获取mongo指定库的所有集合
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.GET(":id/collections", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.Collections)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 获取mongo runCommand
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST(":id/run-command", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.RunCommand)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 执行mongo find命令
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST(":id/command/find", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.FindCommand)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 执行mongo update by id命令
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										updateDocById := req.NewLogInfo("mongo-更新文档").WithSave(true)
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST(":id/command/update-by-id", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WithLog(updateDocById).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.UpdateByIdCommand)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 执行mongo delete by id命令
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										deleteDoc := req.NewLogInfo("mongo-删除文档").WithSave(true)
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST(":id/command/delete-by-id", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WithLog(deleteDoc).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.DeleteByIdCommand)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										// 执行mongo insert 命令
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										insertDoc := req.NewLogInfo("mongo-新增文档").WithSave(true)
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
										m.POST(":id/command/insert", func(c *gin.Context) {
							 | 
						
					
						
							
								
									
										
										
										
											2023-01-14 16:29:52 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
											req.NewCtxWithGin(c).
							 | 
						
					
						
							
								
									
										
										
										
											2022-05-17 20:23:08 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
												WithLog(insertDoc).
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
												Handle(ma.InsertOneCommand)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										})
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |