1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- 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 StudyClient *Study
- func init() {
- StudyClient = new(Study)
- }
- type Study struct {
- basicClient pb.BasicClient
- studyClient pb.StudyClient
- }
- 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)
- s.studyClient = pb.NewStudyClient(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
- }
- func (s *Study) CreateStudy(ctx context.Context, in *pb.StudyRequest) (*pb.StudyReply, error) {
- r, err := s.studyClient.CreateStudy(ctx, in)
- if err != nil {
- slog.Error("[rpc]CreateStudy failed", "err", err)
- return r, err
- }
- return r, nil
- }
|