From 2b7c0450bb67cf787fb315b49153998c6a236a1d Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Mon, 20 Jan 2020 19:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E9=83=A8=E7=BD=B2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy_test | 0 main.go | 20 +++++++++++--------- model/blog.go | 14 +++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 deploy_test diff --git a/deploy_test b/deploy_test new file mode 100644 index 0000000..e69de29 diff --git a/main.go b/main.go index d7be1b8..3520517 100644 --- a/main.go +++ b/main.go @@ -45,7 +45,7 @@ func InitLogs() { func CORSMiddleware(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, UPDATE") c.Writer.Header().Set("Access-Control-Allow-Origin", - "http://172.21.102.193:8080") + "http://localhost:8080") c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With," + @@ -98,16 +98,18 @@ func main() { /** 修改密码**/ api.POST("modify_pass",middle.AuthMiddle,userController.ModifyPasswd) - api.GET("/article/:id",controller.GetArticle) - api.POST("/articles",controller.GetArticles) + api.GET("/article/:id",controller.GetArticle) //获取文章 + api.POST("/articles",controller.GetArticles) // 获取所有文章 api.PUT("/article",controller.AddArticle) // 添加文章 api.GET("article_type",controller.ArticlesType) //获取所有文章分类 - 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("/doc_types",controller.ArticlesTypes) + 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("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型 + + } e := r.Run(":" + strconv.Itoa(config.GetPort())) diff --git a/model/blog.go b/model/blog.go index 3c25df9..2f54d08 100644 --- a/model/blog.go +++ b/model/blog.go @@ -33,13 +33,13 @@ func GetArticlesType() []ArticleType { } func CreateDoc(doc Doc) error { sql := fmt.Sprintf(`INSERT INTO doc ( doc.title, doc.content, doc.author, doc.type ) SELECT -'%s', -'%s', -'%s', -%d -FROM -DUAL -WHERE + '%s', + '%s', + '%s', + %d + FROM + DUAL + WHERE NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1), doc.Author, doc.Type,doc.Title) _, e := db.GetMysqlClient().Query(sql) if nil != e {