123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package service
- import (
- pb "auth-server/rpc_idl/dr_resource_pb"
- "context"
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials/insecure"
- healthpb "google.golang.org/grpc/health/grpc_health_v1"
- "log/slog"
- )
- var basicClient pb.BasicClient
- var configClient pb.ConfigClient
- func init() {
- addr := "localhost:6102"
- conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
- if err != nil {
- slog.Error("NewClient failed:", err)
- panic(err)
- }
- slog.Info("resource conn success", "conn", conn.GetState())
- basicClient = pb.NewBasicClient(conn)
- configClient = pb.NewConfigClient(conn)
- resp, err := healthpb.NewHealthClient(conn).Check(context.Background(), &healthpb.HealthCheckRequest{Service: ""})
- if err != nil {
- slog.Error("Check failed:", err)
- return
- }
- slog.Info("Check success", "resp", resp.GetStatus())
- }
- func GetSoftwareInfo() *pb.SoftwareInfoReply {
- slog.Info("[rpc]SoftwareInfo...")
- r, err := 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 GetConfigOptionList(ctx context.Context, flag string, enable bool) ([]*pb.ConfigOption, error) {
- slog.Info("[rpc]GetConfigOptionList...")
- r, err := configClient.ConfigOptionList(ctx, &pb.ConfigOptionListRequest{
- Flag: flag,
- IsEnabled: enable,
- })
- if err != nil {
- slog.Error("[rpc]GetConfigOptionList failed:", err)
- }
- return r.GetConfigOption(), err
- }
|