Ekaterina Lebedeva
bd588fa2e5
All checks were successful
DCO action / DCO (pull_request) Successful in 41s
Tests and linters / Lint (pull_request) Successful in 1m11s
Tests and linters / Tests (1.22) (pull_request) Successful in 1m11s
Tests and linters / Tests (1.23) (pull_request) Successful in 1m10s
Tests and linters / Tests with -race (pull_request) Successful in 1m23s
Since Go 1.22 a `for` statement with a `range` clause is able to iterate through integer values from zero to an upper limit. gopatch script: @@ var i, e expression @@ -for i := 0; i <= e - 1; i++ { +for i := range e { ... } @@ var i, e expression @@ -for i := 0; i <= e; i++ { +for i := range e + 1 { ... } @@ var i, e expression @@ -for i := 0; i < e; i++ { +for i := range e { ... } Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
95 lines
1.6 KiB
Go
95 lines
1.6 KiB
Go
package status
|
|
|
|
import (
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/grpc"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/message"
|
|
status "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status/grpc"
|
|
)
|
|
|
|
func (x *Detail) ToGRPCMessage() grpc.Message {
|
|
var m *status.Status_Detail
|
|
|
|
if x != nil {
|
|
m = new(status.Status_Detail)
|
|
|
|
m.SetId(x.id)
|
|
m.SetValue(x.val)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func (x *Detail) FromGRPCMessage(m grpc.Message) error {
|
|
v, ok := m.(*status.Status_Detail)
|
|
if !ok {
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
}
|
|
|
|
x.id = v.GetId()
|
|
x.val = v.GetValue()
|
|
|
|
return nil
|
|
}
|
|
|
|
func CodeFromGRPC(v uint32) Code {
|
|
return Code(v)
|
|
}
|
|
|
|
func CodeToGRPC(v Code) uint32 {
|
|
return uint32(v)
|
|
}
|
|
|
|
func (x *Status) ToGRPCMessage() grpc.Message {
|
|
var m *status.Status
|
|
|
|
if x != nil {
|
|
m = new(status.Status)
|
|
|
|
m.SetCode(CodeToGRPC(x.code))
|
|
m.SetMessage(x.msg)
|
|
|
|
var ds []status.Status_Detail
|
|
|
|
if ln := len(x.details); ln > 0 {
|
|
ds = make([]status.Status_Detail, 0, ln)
|
|
|
|
for i := range ln {
|
|
ds = append(ds, *x.details[i].ToGRPCMessage().(*status.Status_Detail))
|
|
}
|
|
}
|
|
|
|
m.SetDetails(ds)
|
|
}
|
|
|
|
return m
|
|
}
|
|
|
|
func (x *Status) FromGRPCMessage(m grpc.Message) error {
|
|
v, ok := m.(*status.Status)
|
|
if !ok {
|
|
return message.NewUnexpectedMessageType(m, v)
|
|
}
|
|
|
|
var (
|
|
ds []Detail
|
|
dsV2 = v.GetDetails()
|
|
)
|
|
|
|
if dsV2 != nil {
|
|
ln := len(dsV2)
|
|
|
|
ds = make([]Detail, ln)
|
|
|
|
for i := range ln {
|
|
if err := ds[i].FromGRPCMessage(&dsV2[i]); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
x.details = ds
|
|
x.msg = v.GetMessage()
|
|
x.code = CodeFromGRPC(v.GetCode())
|
|
|
|
return nil
|
|
}
|