From bc4bdc7414974d9c27b4be9979040ee089953474 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4RNDQIC\\29019" <290198252@qq.com> Date: Sat, 20 Jun 2020 23:15:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=96=87=E7=AB=A0=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=8E=92=E5=BA=8F=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 4 +-- controller/hardware.go | 1 + controller/webhook.go | 18 ++++++++++++++ main.go | 56 ++++++++++++++++++++++-------------------- 4 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 controller/webhook.go diff --git a/controller/blog.go b/controller/blog.go index 0a42d88..7a147b1 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -74,7 +74,7 @@ func GetArticles(c *gin.Context) { is_public = 0 } sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title from doc where is_public = %d " + - "limit %d offset %d",is_public,limit,offset) + "order by id desc limit %d offset %d",is_public,limit,offset) }else{ is_public := 0 if public == "true" { @@ -83,7 +83,7 @@ func GetArticles(c *gin.Context) { is_public = 0 } sql = fmt.Sprintf("SELECT doc.id,doc.author,LEFT(doc.content,50) as content,doc.title,doc.type from doc where doc.type = %d and is_public = %d " + - "limit %d offset %d",req.Type,is_public,limit,offset) + " order by id desc limit %d offset %d",req.Type,is_public,limit,offset) } } log.Print(sql) diff --git a/controller/hardware.go b/controller/hardware.go index c68eab0..cc73993 100644 --- a/controller/hardware.go +++ b/controller/hardware.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" "qiniupkg.com/x/log.v7" ) + func AddHardware(c *gin.Context) { resp := RespBase{"unkown error",-231,nil} defer func() { diff --git a/controller/webhook.go b/controller/webhook.go new file mode 100644 index 0000000..0fab6c9 --- /dev/null +++ b/controller/webhook.go @@ -0,0 +1,18 @@ +package controller + +import "github.com/gin-gonic/gin" +type WebHookController struct { + +} +func (this *WebHookController) PushHook(c *gin.Context) { + resp := RespBase{"unkown error",-231,nil} + defer func() { + c.JSON(200,resp) + }() + repo := c.Param("repo") + if "" == repo{ + return + } + +} + diff --git a/main.go b/main.go index 9b011ff..9b99898 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ var ( userController = controller.UserController{} mailContoller = controller.MailController{} fileController = controller.FileController{} + webhookController = controller.WebHookController{} ) @@ -101,10 +102,10 @@ func main() { /** 删除用户 **/ api.DELETE("/user", userController.DelUser) /** 获取单独用户详情信息 methods(id) **/ - api.GET("/user", middle.AuthMiddle,userController.GetUser) + api.GET("/user", middle.AuthMiddle, userController.GetUser) /** 获取所有用户 **/ - api.GET("/users", middle.AuthMiddle,userController.Users) - api.POST("/search_users",middle.AuthMiddle,userController.SerarchUsers) + api.GET("/users", middle.AuthMiddle, userController.Users) + api.POST("/search_users", middle.AuthMiddle, userController.SerarchUsers) /** 用户登录 **/ api.POST("/login", userController.Login) /** 用户注册 **/ @@ -113,34 +114,37 @@ func main() { api.GET("/logout/:token", userController.Logout) api.POST("/verify", mailContoller.OnSendEmailCode) /** 修改密码**/ - api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd) + api.POST("modify_pass", middle.AuthMiddle, userController.ModifyPasswd) - api.GET("/article/:id",controller.GetArticle) //获取文章 - api.POST("/articles",controller.GetArticles) // 获取所有文章 - api.PUT("/article",controller.AddArticle) // 添加文章 - api.PUT("/article_search",controller.SearchArticle) // 添加文章 - api.GET("article_type",controller.ArticlesType) //获取所有文章分类 - api.PUT("article_type",controller.AddArticleType) - api.DELETE("article_type",controller.DeleteArticleType) + api.GET("/article/:id", controller.GetArticle) //获取文章 + api.POST("/articles", controller.GetArticles) // 获取所有文章 + api.PUT("/article", controller.AddArticle) // 添加文章 + api.PUT("/article_search", controller.SearchArticle) // 添加文章 + api.GET("article_type", controller.ArticlesType) //获取所有文章分类 + api.PUT("article_type", controller.AddArticleType) + api.DELETE("article_type", controller.DeleteArticleType) - api.POST("/article_update",controller.UpdateArtilce) //更新文章 - api.GET("/articleCount",controller.GetArticleCount) //获取所有文章个数 - api.DELETE("/article/:id",controller.DeleteArticle) ////删除文章 - api.POST("/image_upload",fileController.OnUpload) // 上传图片 - api.GET("/image_download/:file",fileController.OnDownLoad) // 下载图片 - api.GET("/image_thumbnail/:file",fileController.OnThumbnail) // 下载图片 - api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型 - api.POST("/hardware",controller.AddHardware) // 新增硬件 - api.GET("/hardware",controller.ReadHardWare) // 读取硬件 - api.DELETE("/hardware",controller.DeleteHardWare) // 读取硬件 - - api.PUT("/file",fileController.OnFileUploadFile) // 上传文件 - api.GET("/file",fileController.DownloadFile) // 下载 文件 - api.GET("/filelist",fileController.FileList) // 文件列表 - api.GET("/fileType",fileController.FileType) // 文件类型 + api.POST("/article_update", controller.UpdateArtilce) //更新文章 + api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数 + api.DELETE("/article/:id", controller.DeleteArticle) ////删除文章 + api.POST("/image_upload", fileController.OnUpload) // 上传图片 + api.GET("/image_download/:file", fileController.OnDownLoad) // 下载图片 + api.GET("/image_thumbnail/:file", fileController.OnThumbnail) // 下载图片 + api.GET("/doc_types", controller.ArticlesTypes) // 获取所有的文章类型 + api.POST("/hardware", controller.AddHardware) // 新增硬件 + api.GET("/hardware", controller.ReadHardWare) // 读取硬件 + api.DELETE("/hardware", controller.DeleteHardWare) // 读取硬件 + api.PUT("/file", fileController.OnFileUploadFile) // 上传文件 + api.GET("/file", fileController.DownloadFile) // 下载 文件 + api.GET("/filelist", fileController.FileList) // 文件列表 + api.GET("/fileType", fileController.FileType) // 文件类型 } + hookapi := r.Group("hookapi") + { + hookapi.POST("/push_hook/:repo",webhookController.PushHook) + } e := r.Run(":" + strconv.Itoa(config.GetPort())) if nil != e { log.Print(e.Error())