From 3f2d6707f55b58e1bbfcc4e2e624bd64d97ebcc1 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Sat, 21 Mar 2020 11:17:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E7=A1=AC=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/blog.go | 2 ++ controller/hardware.go | 27 ++++++++++++++++++++++++ db/elasticEngine.go | 47 +++++++++++++++++++++++++++++++++++------- 3 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 controller/hardware.go diff --git a/controller/blog.go b/controller/blog.go index cde8d1e..90e3a73 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -288,6 +288,8 @@ func DeleteArticle(c *gin.Context) { rsp.Status = 0 rsp.Msg = "OK" } + + func ArticlesTypes(c *gin.Context) { resp := RespBase{"unkown error",-231,nil} defer func() { diff --git a/controller/hardware.go b/controller/hardware.go new file mode 100644 index 0000000..a4c38be --- /dev/null +++ b/controller/hardware.go @@ -0,0 +1,27 @@ +package controller + +import ( + "github.com/gin-gonic/gin" + "time" +) +// this api is based on elasticsearch +type Hardware struct { + ID int32 `json:"id"` + BuyDate time.Time `json:"buy_date"` //购入时间 + Name string `json:"name"` // 名字 + Desc string `json:"desc"` // 描述 + Pic string `json:"pic"` // 图片 + Doc string `json:"doc"` //文档资料 +} + +func AddHardware(c *gin.Context) { + resp := RespBase{"unkown error",-231,nil} + defer func() { + c.JSON(200,resp) + }() + + + resp.Data = docTypes + resp.Msg = "OK" + resp.Status = 0 +} \ No newline at end of file diff --git a/db/elasticEngine.go b/db/elasticEngine.go index 5cf8f40..d0b7d01 100644 --- a/db/elasticEngine.go +++ b/db/elasticEngine.go @@ -48,6 +48,7 @@ func (p *ElkEngine)Create(index string,types string,id string,data interface{}) return errors.New(CREATED_ERROR) } if err != nil { + print(err) return err } }else{ @@ -66,18 +67,50 @@ func (p *ElkEngine)Delete(index string,types string,id string) error{ Id(id). Do() if err != nil { + print(err) return err - } + } if !res.Found{ return errors.New(DELETE_ERROR) - } }else{ return errors.New(ERROR_PTR) } - return nil } -func (p *ElkEngine)Search(index string,types string,id string) (interface{},error){ - - return nil,nil -} \ No newline at end of file +/* + +*/ +func (p *ElkEngine)Query(index string,types string,query elastic.Query,data interface{}) ([]interface{},error) { + if nil != p{ + res, err := p.cli. + Search(index). + Type(types). + Query(query). + Do() + if err != nil { + print(err) + return nil,err + } + //var typ Employee + typ := reflect.TypeOf(data) + return res.Each(typ),nil + }else{ + return nil,errors.New(ERROR_PTR) + } +} + +func (p *ElkEngine)Update(index string,types string,id string,data map[string]interface{}) error { + if nil != p { + _, err := p.cli.Update(). + Index(index). + Type(types). + Id(id). + Doc(data). + Do() + if err != nil { + println(err.Error()) + return err + } + } + return errors.New(ERROR_PTR) +}