package client import ( "context" "fmt" "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/control" controlSvc "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/pkg/service/control/server" "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) type Client struct { svc control.ControlServiceClient key *keys.PrivateKey } type Config struct { Logger *zap.Logger } func New(ctx context.Context, addr string, key *keys.PrivateKey) (*Client, error) { conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, fmt.Errorf("failed to dial s3 gw control api: %w", err) } svc := control.NewControlServiceClient(conn) cli := &Client{ svc: svc, key: key, } return cli, cli.Healthcheck(ctx) } func (c *Client) Healthcheck(ctx context.Context) error { req := &control.HealthCheckRequest{} if err := controlSvc.SignMessage(&c.key.PrivateKey, req); err != nil { return err } res, err := c.svc.HealthCheck(ctx, req) if err != nil { return err } if res.Body.HealthStatus != control.HealthStatus_READY { return fmt.Errorf("service isn't ready, status: %s", res.Body.HealthStatus) } return nil }