git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/api.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	v2netmap "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/netmap"
     8  	rpcapi "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc"
     9  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client"
    10  )
    11  
    12  // interface of FrostFS API server. Exists for test purposes only.
    13  type frostFSAPIServer interface {
    14  	netMapSnapshot(context.Context, v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error)
    15  }
    16  
    17  // wrapper over real client connection which communicates over FrostFS API protocol.
    18  // Provides frostFSAPIServer for Client instances used in real applications.
    19  type coreServer client.Client
    20  
    21  // unifies errors of all RPC.
    22  func rpcErr(e error) error {
    23  	return fmt.Errorf("rpc failure: %w", e)
    24  }
    25  
    26  // executes NetmapService.NetmapSnapshot RPC declared in FrostFS API protocol
    27  // using underlying client.Client.
    28  func (x *coreServer) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
    29  	resp, err := rpcapi.NetMapSnapshot((*client.Client)(x), &req, client.WithContext(ctx))
    30  	if err != nil {
    31  		return nil, rpcErr(err)
    32  	}
    33  
    34  	return resp, nil
    35  }