pb_protocol.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package service
  2. import (
  3. "context"
  4. "log/slog"
  5. )
  6. import (
  7. "google.golang.org/grpc"
  8. "google.golang.org/grpc/credentials/insecure"
  9. )
  10. import (
  11. "auth-server/common"
  12. pb "auth-server/rpc_idl/dr_protocol_pb"
  13. )
  14. var ProtocolService *Protocol
  15. func init() {
  16. ProtocolService = new(Protocol)
  17. }
  18. type Protocol struct {
  19. basicClient pb.BasicClient
  20. protocolClient pb.ProtocolClient
  21. }
  22. func (s *Protocol) Setup() {
  23. conn, err := grpc.NewClient(common.ServerConfig.Protocol, grpc.WithTransportCredentials(insecure.NewCredentials()))
  24. if err != nil {
  25. slog.Error("NewClient failed:", err)
  26. panic(err)
  27. }
  28. slog.Info("protocol conn success", "conn", conn.GetState())
  29. s.basicClient = pb.NewBasicClient(conn)
  30. s.protocolClient = pb.NewProtocolClient(conn)
  31. }
  32. func (s *Protocol) GetSoftwareInfo() *pb.SoftwareInfoReply {
  33. slog.Info("[rpc]SoftwareInfo...")
  34. r, err := s.basicClient.SoftwareInfo(context.Background(), &pb.EmptyRequest{})
  35. if err != nil {
  36. slog.Error("[rpc]SoftwareInfo failed:", err)
  37. return &pb.SoftwareInfoReply{
  38. Module: "",
  39. Desc: "",
  40. Build: "",
  41. Version: "",
  42. }
  43. }
  44. return r
  45. }
  46. func (s *Protocol) GetPatientType(ctx context.Context, isEnabled *bool) (*pb.PatientTypeReply, error) {
  47. slog.Info("[rpc]GetPatientType...")
  48. r, err := s.protocolClient.GetPatientType(ctx, &pb.PatientTypeRequest{
  49. IsEnabled: isEnabled,
  50. })
  51. if err != nil {
  52. slog.Error("[rpc]GetPatientType failed:", err)
  53. }
  54. slog.Info("[rpc]GetPatientType result:", "rows", len(r.PatientTypeList))
  55. return r, err
  56. }
  57. func (s *Protocol) GetBodyPart(ctx context.Context, patientType *string, category *string, isEnabled *bool) (*pb.BodyPartReply, error) {
  58. slog.Info("[rpc]GetBodyPart...")
  59. r, err := s.protocolClient.GetBodyPart(ctx, &pb.BodyPartRequest{
  60. PatientType: patientType,
  61. Category: category,
  62. IsEnabled: isEnabled,
  63. })
  64. if err != nil {
  65. slog.Error("[rpc]GetPatientType failed:", err)
  66. }
  67. return r, err
  68. }