pb_study.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package service
  2. import (
  3. "context"
  4. "log/slog"
  5. "time"
  6. )
  7. import (
  8. "google.golang.org/grpc"
  9. "google.golang.org/grpc/credentials/insecure"
  10. )
  11. import (
  12. "auth-server/common"
  13. pb "auth-server/rpc_idl/dr_study_pb"
  14. )
  15. var StudyService *Study
  16. func init() {
  17. StudyService = new(Study)
  18. }
  19. type Study struct {
  20. basicClient pb.BasicClient
  21. }
  22. func (s *Study) Setup() {
  23. conn, err := grpc.NewClient(common.ServerConfig.Study, grpc.WithTransportCredentials(insecure.NewCredentials()))
  24. if err != nil {
  25. slog.Error("NewClient failed:", err)
  26. panic(err)
  27. }
  28. slog.Info("study conn success", "conn", conn.GetState())
  29. s.basicClient = pb.NewBasicClient(conn)
  30. }
  31. func (s *Study) GetSoftwareInfo() *pb.SoftwareInfoReply {
  32. slog.Info("[rpc]SoftwareInfo...")
  33. ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
  34. defer cancel()
  35. r, err := s.basicClient.SoftwareInfo(ctx, &pb.EmptyRequest{})
  36. if err != nil {
  37. slog.Error("[rpc]SoftwareInfo failed", "err", err)
  38. return &pb.SoftwareInfoReply{
  39. Module: "",
  40. Desc: "",
  41. Build: "",
  42. Version: "",
  43. }
  44. }
  45. return r
  46. }