forked from TrueCloudLab/frostfs-api-go
[#376] status: Remove pointer from Detail
slice
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
0cab407378
commit
43fd3cfb4f
5 changed files with 14 additions and 20 deletions
|
@ -67,7 +67,7 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) {
|
||||||
d.SetID(detailAccessDeniedDesc)
|
d.SetID(detailAccessDeniedDesc)
|
||||||
d.SetValue([]byte(desc))
|
d.SetValue([]byte(desc))
|
||||||
|
|
||||||
st.AppendDetails(&d)
|
st.AppendDetails(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,27 +71,21 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ds []*Detail
|
ds []Detail
|
||||||
dsV2 = v.GetDetails()
|
dsV2 = v.GetDetails()
|
||||||
)
|
)
|
||||||
|
|
||||||
if dsV2 != nil {
|
if dsV2 != nil {
|
||||||
ln := len(dsV2)
|
ln := len(dsV2)
|
||||||
|
|
||||||
ds = make([]*Detail, 0, ln)
|
ds = make([]Detail, ln)
|
||||||
|
|
||||||
for i := 0; i < ln; i++ {
|
for i := 0; i < ln; i++ {
|
||||||
var p *Detail
|
|
||||||
|
|
||||||
if dsV2[i] != nil {
|
if dsV2[i] != nil {
|
||||||
p = new(Detail)
|
if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil {
|
||||||
|
|
||||||
if err := p.FromGRPCMessage(dsV2[i]); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ds = append(ds, p)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ func (x *Status) StableMarshal(buf []byte) ([]byte, error) {
|
||||||
offset += n
|
offset += n
|
||||||
|
|
||||||
for i := range x.details {
|
for i := range x.details {
|
||||||
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], x.details[i])
|
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func (x *Status) StableSize() (size int) {
|
||||||
size += protoutil.StringSize(statusMsgFNum, x.msg)
|
size += protoutil.StringSize(statusMsgFNum, x.msg)
|
||||||
|
|
||||||
for i := range x.details {
|
for i := range x.details {
|
||||||
size += protoutil.NestedStructureSize(statusDetailsFNum, x.details[i])
|
size += protoutil.NestedStructureSize(statusDetailsFNum, &x.details[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
return size
|
return size
|
||||||
|
|
|
@ -17,13 +17,13 @@ func Detail(empty bool) *status.Detail {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Details returns several status.Detail messages filled with static random values.
|
// Details returns several status.Detail messages filled with static random values.
|
||||||
func Details(empty bool) []*status.Detail {
|
func Details(empty bool) []status.Detail {
|
||||||
var res []*status.Detail
|
var res []status.Detail
|
||||||
|
|
||||||
if !empty {
|
if !empty {
|
||||||
res = append(res,
|
res = append(res,
|
||||||
Detail(false),
|
*Detail(false),
|
||||||
Detail(false),
|
*Detail(false),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ type Status struct {
|
||||||
|
|
||||||
msg string
|
msg string
|
||||||
|
|
||||||
details []*Detail
|
details []Detail
|
||||||
}
|
}
|
||||||
|
|
||||||
// Code returns code of the Status.
|
// Code returns code of the Status.
|
||||||
|
@ -104,7 +104,7 @@ func (x *Status) NumberOfDetails() int {
|
||||||
func (x *Status) IterateDetails(f func(*Detail) bool) {
|
func (x *Status) IterateDetails(f func(*Detail) bool) {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
for i := range x.details {
|
for i := range x.details {
|
||||||
if f(x.details[i]) {
|
if f(&x.details[i]) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,14 +119,14 @@ func (x *Status) ResetDetails() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendDetails appends the list of details to the Status.
|
// AppendDetails appends the list of details to the Status.
|
||||||
func (x *Status) AppendDetails(ds ...*Detail) {
|
func (x *Status) AppendDetails(ds ...Detail) {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
x.details = append(x.details, ds...)
|
x.details = append(x.details, ds...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStatusDetails sets Detail list of the Status.
|
// SetStatusDetails sets Detail list of the Status.
|
||||||
func SetStatusDetails(dst *Status, ds []*Detail) {
|
func SetStatusDetails(dst *Status, ds []Detail) {
|
||||||
dst.ResetDetails()
|
dst.ResetDetails()
|
||||||
dst.AppendDetails(ds...)
|
dst.AppendDetails(ds...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue