Aleksey Savchuk
a4fb7f085b
All checks were successful
Tests and linters / Run gofumpt (pull_request) Successful in 2m36s
Pre-commit hooks / Pre-commit (pull_request) Successful in 3m3s
Vulncheck / Vulncheck (pull_request) Successful in 2m50s
Tests and linters / Tests (1.22) (pull_request) Successful in 3m3s
DCO action / DCO (pull_request) Successful in 2m47s
Tests and linters / Lint (pull_request) Successful in 3m39s
Tests and linters / Staticcheck (pull_request) Successful in 3m37s
Tests and linters / Tests (1.23) (pull_request) Successful in 3m43s
Build / Build Components (1.22) (pull_request) Successful in 3m32s
Build / Build Components (1.23) (pull_request) Successful in 3m32s
Tests and linters / gopls check (pull_request) Successful in 4m10s
Tests and linters / Tests with -race (pull_request) Successful in 4m16s
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
82 lines
2.3 KiB
Go
82 lines
2.3 KiB
Go
package container
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container"
|
|
containerGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
|
|
containersvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/container"
|
|
)
|
|
|
|
// Server wraps FrostFS API Container service and
|
|
// provides gRPC Container service server interface.
|
|
type Server struct {
|
|
srv containersvc.Server
|
|
}
|
|
|
|
// New creates, initializes and returns Server instance.
|
|
func New(c containersvc.Server) *Server {
|
|
return &Server{
|
|
srv: c,
|
|
}
|
|
}
|
|
|
|
// Put converts gRPC PutRequest message and passes it to internal Container service.
|
|
func (s *Server) Put(ctx context.Context, req *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
|
|
putReq := new(container.PutRequest)
|
|
if err := putReq.FromGRPCMessage(req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := s.srv.Put(ctx, putReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.PutResponse), nil
|
|
}
|
|
|
|
// Delete converts gRPC DeleteRequest message and passes it to internal Container service.
|
|
func (s *Server) Delete(ctx context.Context, req *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
|
|
delReq := new(container.DeleteRequest)
|
|
if err := delReq.FromGRPCMessage(req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := s.srv.Delete(ctx, delReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.DeleteResponse), nil
|
|
}
|
|
|
|
// Get converts gRPC GetRequest message and passes it to internal Container service.
|
|
func (s *Server) Get(ctx context.Context, req *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
|
|
getReq := new(container.GetRequest)
|
|
if err := getReq.FromGRPCMessage(req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := s.srv.Get(ctx, getReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.GetResponse), nil
|
|
}
|
|
|
|
// List converts gRPC ListRequest message and passes it to internal Container service.
|
|
func (s *Server) List(ctx context.Context, req *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
|
|
listReq := new(container.ListRequest)
|
|
if err := listReq.FromGRPCMessage(req); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := s.srv.List(ctx, listReq)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.ListResponse), nil
|
|
}
|