protocol.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package gate
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "git.getensh.com/common/gopkgs/logger"
  7. "go.uber.org/zap"
  8. "google.golang.org/grpc/status"
  9. pb_v1 "property-device/pb/v1"
  10. "property-device/utils/gate_utils"
  11. )
  12. func GateProtocols(ctx context.Context, req *pb_v1.GateProtocolsRequest) (reply *pb_v1.GateProtocolsReply, err error) {
  13. reply = &pb_v1.GateProtocolsReply{}
  14. // 捕获各个task中的异常并返回给调用者
  15. defer func() {
  16. if r := recover(); r != nil {
  17. err = fmt.Errorf("%+v", r)
  18. e := &status.Status{}
  19. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  20. logger.Error("err",
  21. zap.String("system_err", err.Error()),
  22. zap.Stack("stacktrace"))
  23. }
  24. }
  25. }()
  26. reply.List = make([]*pb_v1.GateProtocolData, len(gate_utils.GateProtocolFuntionMap))
  27. i := 0
  28. for k, array := range gate_utils.GateProtocolFuntionMap {
  29. reply.List[i] = &pb_v1.GateProtocolData{
  30. Protocol: k,
  31. Desc: gate_utils.GateProtocolNameMap[k],
  32. QcodeSupport: array[0],
  33. FaceSupport: array[1],
  34. CardSupport: array[2],
  35. }
  36. i++
  37. }
  38. return reply, nil
  39. }