liuxiaolong
2019-06-26 021679b25d25b608380be9e50d09184a3f49eb62
service/FaceSdkService.go
@@ -1,33 +1,50 @@
package service
import (
   "basic.com/pubsub/protomsg.git"
   "basic.com/valib/deliver.git"
   "github.com/gin-gonic/gin/internal/json"
   "encoding/json"
   "fmt"
   "github.com/gogo/protobuf/proto"
)
type ImageSource struct {
   Id string `json:"id"`
   Data []byte `json:"data"`
}
const (
   Url_Service_PUSH = "tcp:///tmp///webserver-2.ipc"
   Url_Service_PULL = "tcp:///tmp///webserver-1.ipc"
)
var imgChan chan ImageSource
func PushImgMsg(is ImageSource){
   imgChan <- is
var imgPushChan chan protomsg.Recvmsg
func PushImgMsg(is protomsg.Recvmsg){
   imgPushChan <- is
}
var resultMap map[string]protomsg.SdkMessage
func InitService(){
   imgChan = make(chan ImageSource)
   client := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
   imgPushChan = make(chan protomsg.Recvmsg)
   client_push := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
   client_pull := deliver.NewClient(deliver.PushPull, Url_Service_PULL)
   for {
      select {
      case is := <- imgChan:
         b, _ := json.Marshal(is)
         client.Send(b)
         case is := <- imgPushChan:
            b, _ := json.Marshal(is)
            client_push.Send(b)
      }
   }
   //接收人脸提取结果
   for {
      resultBytes, err := client_pull.Recv()
      if err !=nil{
         fmt.Println("pull err:",err)
         continue
      }
      rMsg := protomsg.SdkMessage{}
      if err := proto.Unmarshal(resultBytes, &rMsg);err !=nil{
         fmt.Println(rMsg)
         resultMap[rMsg.Cid] = rMsg
      }
   }