From 0cc8d28ff6bae56fe8f4388aedd4ab1d46a11c96 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 24 七月 2019 19:03:39 +0800
Subject: [PATCH] config compServerList
---
controllers/fileController.go | 81 +++++++++++++++++++++++-----------------
config/dev.yaml | 3 +
extend/config/config.go | 8 ++++
3 files changed, 58 insertions(+), 34 deletions(-)
diff --git a/config/dev.yaml b/config/dev.yaml
index cc83bd5..70f52c1 100644
--- a/config/dev.yaml
+++ b/config/dev.yaml
@@ -5,6 +5,9 @@
url: http://127.0.0.1:8080
imageUrl: http://192.168.1.203:6080
networkAdapter: enp59s0f1
+compare:
+ url:
+ - 192.168.1.66:40010
weedfs:
ip: 192.168.1.203
uploadport: 6333
diff --git a/controllers/fileController.go b/controllers/fileController.go
index 8f97e3e..2123a1b 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -105,7 +105,13 @@
}
var faceExtractedMap = make(map[string]FaceExtract,0)
-// @Description 浜鸿劯鎻愬彇
+// @Summary 浜鸿劯鎻愬彇
+// @Description 浜鸿劯鎻愬彇
+// @Produce json
+// @Tags 浠ュ浘鎼滃浘
+// @Param file formData file true "浜哄憳鍥剧墖"
+// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}"
// @Router /data/api-v/dbperson/faceExtract [POST]
func (controller FileController) FaceExtract(c *gin.Context) {
file, _, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑 'fileObjName':'image'
@@ -132,17 +138,20 @@
urlArr = append(urlArr, weedFilePath)
}
}
- if len(urlArr) == 0{
- util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯")
- } else {
- util.ResponseFormat(c,code.Success,urlArr)
- }
+
+ util.ResponseFormat(c,code.Success,urlArr)
} else {
util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯")
}
}
-// @Description 浠ュ浘鎼滃浘
+// @Summary 浠ュ浘鎼滃浘
+// @Description 浠ュ浘鎼滃浘
+// @Produce json
+// @Tags 浠ュ浘鎼滃浘
+// @Param url formData string true "url"
+// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}"
// @Router /data/api-v/dbperson/searchByPhoto [POST]
func (controller FileController) SearchByPhoto(c *gin.Context) {
photoUrl := c.Request.FormValue("url")
@@ -154,8 +163,6 @@
util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
return
} else {
- reqUrl := "tcp://192.168.1.66:40010"
- reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
arg := protomsg.CompareArgs{
FaceFeature:face.FaceBytes,
CompareThreshold:0.2,
@@ -165,32 +172,38 @@
util.ResponseFormat(c, code.ComError, "璇锋眰marshal澶辫触")
return
}
- err = reqClient.Send(b)
- if err !=nil{
- util.ResponseFormat(c, code.ComError, "姣斿鏈嶅姟璇锋眰澶辫触")
- return
+ compServerList := config.CompServerInfo.Url
+ fmt.Println("compServerList:", compServerList)
+ resultList :=make([]protomsg.Dbperson,0)
+ for _,str :=range compServerList{
+ reqUrl := "tcp://"+str
+ reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
+ err = reqClient.Send(b)
+ if err !=nil{
+ continue
+ }
+ resultB, err := reqClient.Recv()
+ if err !=nil{
+ continue
+ }
+ m :=make(map[string]float32,0)
+ err = json.Unmarshal(resultB, &m)
+ if err !=nil{
+ continue
+ }
+ personIds := make([]string,len(m))
+ for k,_ :=range m{
+ personIds = append(personIds,k)
+ }
+ esServerIp := config.EsInfo.Masterip
+ esServerPort := config.EsInfo.Httpport
+ index := config.EsInfo.EsIndex.Dbtablepersons.IndexName
+ dbpeople, e := esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort)
+ if e ==nil{
+ resultList = append(resultList,dbpeople...)
+ }
}
- resultB, err := reqClient.Recv()
- if err !=nil{
- util.ResponseFormat(c, code.ComError, "姣斿鏈嶅姟鍝嶅簲澶辫触")
- return
- }
- m :=make(map[string]float32,0)
- err = json.Unmarshal(resultB, &m)
- if err !=nil{
- util.ResponseFormat(c, code.ComError, "result Unmarshal err")
- return
- }
- personIds := make([]string,len(m))
- for k,_ :=range m{
- personIds = append(personIds,k)
- }
- dbpeople, e := esApi.Dbpersoninfosbyid(personIds, "dbtablepersons", "192.168.1.182", "9200")
- if e !=nil{
- util.ResponseFormat(c, code.ComError, "result es query err")
- } else {
- util.ResponseFormat(c,code.Success,dbpeople)
- }
+ util.ResponseFormat(c,code.Success,resultList)
}
}
diff --git a/extend/config/config.go b/extend/config/config.go
index 3de0097..fdde022 100644
--- a/extend/config/config.go
+++ b/extend/config/config.go
@@ -63,6 +63,13 @@
var DBconf = &database{}
+type CompareServer struct {
+ Url []string `mapstructure:"url"`
+}
+
+var CompServerInfo = &CompareServer{}
+
+
// Init is an exported method that takes the environment starts the viper
// (external lib) and returns the configuration struct.
func Init(env string) {
@@ -80,4 +87,5 @@
viper.UnmarshalKey("redis", RedisConf)
viper.UnmarshalKey("database", DBconf)
viper.UnmarshalKey("weedfs", WeedFs)
+ viper.UnmarshalKey("compare", CompServerInfo)
}
--
Gitblit v1.8.0