package service import ( "context" "log/slog" ) import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) import ( "auth-server/common" pb "auth-server/rpc_idl/dr_resource_pb" ) var ResourceService *Resource func init() { ResourceService = new(Resource) } type Resource struct { basicClient pb.BasicClient configClient pb.ConfigClient } func (s *Resource) Setup() { conn, err := grpc.NewClient(common.ServerConfig.Resource, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { slog.Error("NewClient failed:", err) panic(err) } slog.Info("resource conn success", "conn", conn.GetState()) s.basicClient = pb.NewBasicClient(conn) s.configClient = pb.NewConfigClient(conn) } func (s *Resource) GetSoftwareInfo() *pb.SoftwareInfoReply { slog.Info("[rpc]SoftwareInfo...") r, err := s.basicClient.SoftwareInfo(context.Background(), &pb.EmptyRequest{}) if err != nil { slog.Error("[rpc]SoftwareInfo failed:", err) return &pb.SoftwareInfoReply{ Module: "", Desc: "", Build: "", Version: "", } } return r } func (s *Resource) GetConfigOptionList(ctx context.Context, flag string, enable bool) ([]*pb.ConfigOption, error) { slog.Info("[rpc]GetConfigOptionList...") r, err := s.configClient.ConfigOptionList(ctx, &pb.ConfigOptionListRequest{ Flag: flag, IsEnabled: enable, }) if err != nil { slog.Error("[rpc]GetConfigOptionList failed:", err) } return r.GetConfigOption(), err }