package service import ( "context" "log/slog" "time" ) import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) import ( "auth-server/common" pb "auth-server/rpc_idl/dr_study_pb" ) var StudyService *Study func init() { StudyService = new(Study) } type Study struct { basicClient pb.BasicClient } func (s *Study) Setup() { conn, err := grpc.NewClient(common.ServerConfig.Study, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { slog.Error("NewClient failed:", err) panic(err) } slog.Info("study conn success", "conn", conn.GetState()) s.basicClient = pb.NewBasicClient(conn) } func (s *Study) GetSoftwareInfo() *pb.SoftwareInfoReply { slog.Info("[rpc]SoftwareInfo...") ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond) defer cancel() r, err := s.basicClient.SoftwareInfo(ctx, &pb.EmptyRequest{}) if err != nil { slog.Error("[rpc]SoftwareInfo failed", "err", err) return &pb.SoftwareInfoReply{ Module: "", Desc: "", Build: "", Version: "", } } return r }