接口修改,size为0,获取全部硬件信息
parent
cb08c725ca
commit
6baf8c4546
|
@ -48,6 +48,9 @@ func ReadHardWare(c *gin.Context) {
|
|||
log.Error(e.Error())
|
||||
return
|
||||
}
|
||||
//limit,offset := GetPageParaFromQuery(c)
|
||||
|
||||
limit,offset := GetPageParaFromQuery(c)
|
||||
hardware,e := model.GetHardwares(limit,offset)
|
||||
rsp.Data = hardware
|
||||
rsp.Msg = "OK"
|
||||
rsp.Status = 0
|
||||
}
|
||||
|
|
|
@ -70,6 +70,19 @@ func (p *ElkEngine)Query(index string,
|
|||
types string,query elastic.Query,data interface{},
|
||||
limit int,offset int) ([]interface{},error) {
|
||||
if nil != p{
|
||||
if(limit == 0){
|
||||
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{
|
||||
res, err := p.cli.
|
||||
Search(index).
|
||||
Type(types).
|
||||
|
@ -81,6 +94,8 @@ func (p *ElkEngine)Query(index string,
|
|||
//var typ Employee
|
||||
typ := reflect.TypeOf(data)
|
||||
return res.Each(typ),nil
|
||||
}
|
||||
|
||||
}else{
|
||||
return nil,errors.New(ERROR_PTR)
|
||||
}
|
||||
|
@ -150,7 +165,5 @@ func (p *ElkEngine)InitMapping(esIndexName string, esTypeName string, typeMappin
|
|||
// Not acknowledged
|
||||
return errors.New("create mapping fail, esIndexName:" + esIndexName + ", esTypeName:" + esTypeName + ", not Ack nowledged")
|
||||
}
|
||||
|
||||
|
||||
return err
|
||||
}
|
2
main.go
2
main.go
|
@ -126,7 +126,7 @@ func main() {
|
|||
api.GET("/doc_types",controller.ArticlesTypes) // 获取所有的文章类型
|
||||
|
||||
api.POST("/hardware",controller.AddHardware) // 新增硬件
|
||||
api.GET("/hardware",controller.ReadHardWare) // 新增硬件
|
||||
api.GET("/hardware",controller.ReadHardWare) // 读取硬件
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ func (this *Hardware )CreateHardware( ) error{
|
|||
if nil == this{
|
||||
return errors.New("null pointer")
|
||||
}
|
||||
e := db.GetElastic().Create("hardware","0","sdfasdfasd",*this)
|
||||
e := db.GetElastic().Create("hardware","0","",*this)
|
||||
if nil != e{
|
||||
log.Print(e.Error())
|
||||
return e
|
||||
|
@ -43,7 +43,14 @@ func (this *Hardware )CreateHardware( ) error{
|
|||
return nil;
|
||||
}
|
||||
|
||||
func (this *Hardware)Hardwares() ([]Hardware,error){
|
||||
|
||||
return nil,nil
|
||||
func GetHardwares(limit int,size int) ([]Hardware,error){
|
||||
var ret []Hardware
|
||||
data,e := db.GetElastic().Query("hardware","0",nil,Hardware{},limit,size)
|
||||
if nil != e{
|
||||
return nil,e
|
||||
}
|
||||
for _,v := range data{
|
||||
ret = append(ret,v.(Hardware))
|
||||
}
|
||||
return ret,nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue