2022-03-07 11:39:49 +00:00
|
|
|
/*
|
2022-12-29 10:46:18 +00:00
|
|
|
Package client provides FrostFS API client implementation.
|
2022-03-07 11:39:49 +00:00
|
|
|
|
|
|
|
The main component is Client type. It is a virtual connection to the network
|
|
|
|
and provides methods for executing operations on the server.
|
|
|
|
|
|
|
|
Create client instance:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
var c client.Client
|
|
|
|
|
|
|
|
Initialize client state:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
var prm client.PrmInit
|
|
|
|
prm.SetDefaultPrivateKey(key)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
c.Init(prm)
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
Connect to the FrostFS server:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
var prm client.PrmDial
|
|
|
|
prm.SetServerURI("localhost:8080")
|
|
|
|
prm.SetDefaultPrivateKey(key)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
err := c.Dial(prm)
|
|
|
|
// ...
|
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
Execute FrostFS operation on the server:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
var prm client.PrmContainerPut
|
|
|
|
prm.SetContainer(cnr)
|
|
|
|
// ...
|
|
|
|
|
|
|
|
res, err := c.ContainerPut(context.Background(), prm)
|
|
|
|
err := c.Dial(dialPrm)
|
|
|
|
if err == nil {
|
|
|
|
err = apistatus.ErrFromStatus(res.Status())
|
|
|
|
}
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Consume custom service of the server:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
syntax = "proto3";
|
|
|
|
|
|
|
|
service CustomService {
|
|
|
|
rpc CustomRPC(CustomRPCRequest) returns (CustomRPCResponse);
|
|
|
|
}
|
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
import "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/client"
|
|
|
|
import "github.com/TrueCloudLab/frostfs-api-go/v2/rpc/common"
|
2022-03-07 11:39:49 +00:00
|
|
|
|
|
|
|
req := new(CustomRPCRequest)
|
|
|
|
// ...
|
|
|
|
resp := new(CustomRPCResponse)
|
|
|
|
|
|
|
|
err := c.ExecRaw(func(c *client.Client) error {
|
|
|
|
return client.SendUnary(c, common.CallMethodInfo{
|
|
|
|
Service: "CustomService",
|
|
|
|
Name: "CustomRPC",
|
|
|
|
}, req, resp)
|
|
|
|
})
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Close the connection:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-03-07 11:39:49 +00:00
|
|
|
err := c.Close()
|
|
|
|
// ...
|
|
|
|
|
|
|
|
Note that it's not allowed to override Client behaviour directly: the parameters
|
|
|
|
for the all operations are write-only and the results of the all operations are
|
|
|
|
read-only. To be able to override client behavior (e.g. for tests), abstract it
|
|
|
|
with an interface:
|
2022-08-24 14:17:40 +00:00
|
|
|
|
2022-12-13 14:36:35 +00:00
|
|
|
import "github.com/TrueCloudLab/frostfs-sdk-go/client"
|
2022-03-07 11:39:49 +00:00
|
|
|
|
2022-12-29 10:46:18 +00:00
|
|
|
type FrostFSClient interface {
|
2022-03-07 11:39:49 +00:00
|
|
|
// Operations according to the application needs
|
|
|
|
CreateContainer(context.Context, container.Container) error
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
type client struct {
|
|
|
|
c *client.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x *client) CreateContainer(context.Context, container.Container) error {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
package client
|