pb_study.go 995 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_study_pb"
  13. )
  14. var StudyService *Study
  15. func init() {
  16. StudyService = new(Study)
  17. }
  18. type Study struct {
  19. basicClient pb.BasicClient
  20. }
  21. func (s *Study) Setup() {
  22. conn, err := grpc.NewClient(common.ServerConfig.Study, grpc.WithTransportCredentials(insecure.NewCredentials()))
  23. if err != nil {
  24. slog.Error("NewClient failed:", err)
  25. panic(err)
  26. }
  27. slog.Info("study conn success", "conn", conn.GetState())
  28. s.basicClient = pb.NewBasicClient(conn)
  29. }
  30. func (s *Study) GetSoftwareInfo() *pb.SoftwareInfoReply {
  31. slog.Info("[rpc]SoftwareInfo...")
  32. r, err := s.basicClient.SoftwareInfo(context.Background(), &pb.EmptyRequest{})
  33. if err != nil {
  34. slog.Error("[rpc]SoftwareInfo failed:", err)
  35. return &pb.SoftwareInfoReply{
  36. Module: "",
  37. Desc: "",
  38. Build: "",
  39. Version: "",
  40. }
  41. }
  42. return r
  43. }