From 4e2ff25d382fec47c4667967217771d0c25e8470 Mon Sep 17 00:00:00 2001 From: a74589669 <290198252@qq.com> Date: Sat, 7 Sep 2019 00:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96=E6=89=80?= =?UTF-8?q?=E6=9C=89=E6=96=87=E7=AB=A0=E5=88=86=E7=B1=BB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 20 ++++++++++++++++++++ main.go | 3 ++- model/blog.go | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 834393d..d53394b 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -219,4 +219,24 @@ func DeleteArticle(c *gin.Context) { rsp.Data = id rsp.Status = 0 rsp.Msg = "OK" +} +func ArticlesTypes(c *gin.Context) { + resp := RespBase{"unkown error",-231,nil} + defer func() { + c.JSON(200,resp) + }() + type DocType struct { + Id int64 `sql:"id"` + TypeName string `sql:"type_name"` + } + docTypes := []DocType{} + e := db.GetMysqlClient().Query2("select * from doc_type", + &docTypes) + if nil != e{ + log.Print(e.Error()) + return + } + resp.Data = docTypes + resp.Msg = "OK" + resp.Status = 0 } \ No newline at end of file diff --git a/main.go b/main.go index 3fb7a36..0b6dfb2 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,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") + c.Writer.Header().Set("Access-Control-Allow-Origin", "http://localhost:8080") c.Writer.Header().Set("Access-Control-Max-Age", "86400") c.Writer.Header().Set("Access-Control-Allow-Headers", "X-Requested-With," + @@ -106,6 +106,7 @@ func main() { 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 4501dfc..a51604c 100644 --- a/model/blog.go +++ b/model/blog.go @@ -67,4 +67,4 @@ func DeleteDoc(id int64) error{ return e } return nil -} \ No newline at end of file +}