123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package service
- import (
- "context"
- "log/slog"
- "time"
- )
- import (
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials/insecure"
- "google.golang.org/protobuf/types/known/emptypb"
- )
- import (
- "auth-server/common"
- "auth-server/logger"
- 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()),
- grpc.WithUnaryInterceptor(logger.GRPCLoggerClientInterceptor(logger.WithGroup("grpc_c[study]"))),
- )
- 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 {
- ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
- defer cancel()
- r, err := s.basicClient.SoftwareInfo(ctx, &emptypb.Empty{})
- if err != nil {
- 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)
- return r, err
- }
- func (s *Study) GetStudy(ctx context.Context, id *string) (*pb.StudyReply, error) {
- r, err := s.studyClient.GetStudy(ctx, &pb.IDRequest{
- InstanceId: id,
- })
- return r, err
- }
- func (s *Study) CreateImage(ctx context.Context, in *pb.CreateImageRequest) (*pb.CreateImageReply, error) {
- r, err := s.studyClient.CreateImage(ctx, in)
- return r, err
- }
- func (s *Study) CopyImage(ctx context.Context, in *pb.IDRequest) (*pb.CreateImageReply, error) {
- r, err := s.studyClient.CopyImage(ctx, in)
- return r, err
- }
- func (s *Study) SortImage(ctx context.Context, in *pb.SortRequest) (*emptypb.Empty, error) {
- r, err := s.studyClient.SortImage(ctx, in)
- return r, err
- }
- func (s *Study) DeleteImage(ctx context.Context, id *string) (*emptypb.Empty, error) {
- r, err := s.studyClient.DeleteImage(ctx, &pb.IDRequest{
- InstanceId: id,
- })
- return r, err
- }
|