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) +}