git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/doc.go (about) 1 /* 2 Package client provides FrostFS API client implementation. 3 4 The main component is Client type. It is a virtual connection to the network 5 and provides methods for executing operations on the server. 6 7 Create client instance: 8 9 var c client.Client 10 11 Initialize client state: 12 13 var prm client.PrmInit 14 prm.SetDefaultPrivateKey(key) 15 // ... 16 17 c.Init(prm) 18 19 Connect to the FrostFS server: 20 21 var prm client.PrmDial 22 prm.SetServerURI("localhost:8080") 23 prm.SetDefaultPrivateKey(key) 24 // ... 25 26 err := c.Dial(prm) 27 // ... 28 29 Execute FrostFS operation on the server: 30 31 var prm client.PrmContainerPut 32 prm.SetContainer(cnr) 33 // ... 34 35 res, err := c.ContainerPut(context.Background(), prm) 36 err := c.Dial(dialPrm) 37 if err == nil { 38 err = apistatus.ErrFromStatus(res.Status()) 39 } 40 // ... 41 42 Consume custom service of the server: 43 44 syntax = "proto3"; 45 46 service CustomService { 47 rpc CustomRPC(CustomRPCRequest) returns (CustomRPCResponse); 48 } 49 50 import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" 51 import "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/common" 52 53 req := new(CustomRPCRequest) 54 // ... 55 resp := new(CustomRPCResponse) 56 57 err := c.ExecRaw(func(c *client.Client) error { 58 return client.SendUnary(c, common.CallMethodInfo{ 59 Service: "CustomService", 60 Name: "CustomRPC", 61 }, req, resp) 62 }) 63 // ... 64 65 Close the connection: 66 67 err := c.Close() 68 // ... 69 70 Note that it's not allowed to override Client behaviour directly: the parameters 71 for the all operations are write-only and the results of the all operations are 72 read-only. To be able to override client behavior (e.g. for tests), abstract it 73 with an interface: 74 75 import "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" 76 77 type FrostFSClient interface { 78 // Operations according to the application needs 79 CreateContainer(context.Context, container.Container) error 80 // ... 81 } 82 83 type client struct { 84 c *client.Client 85 } 86 87 func (x *client) CreateContainer(context.Context, container.Container) error { 88 // ... 89 } 90 */ 91 package client