diff --git a/object/status.go b/object/status.go index 067c372d..dc37ad25 100644 --- a/object/status.go +++ b/object/status.go @@ -67,7 +67,7 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) { d.SetID(detailAccessDeniedDesc) d.SetValue([]byte(desc)) - st.AppendDetails(&d) + st.AppendDetails(d) } } diff --git a/status/convert.go b/status/convert.go index 8195096d..50145ef9 100644 --- a/status/convert.go +++ b/status/convert.go @@ -71,27 +71,21 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error { } var ( - ds []*Detail + ds []Detail dsV2 = v.GetDetails() ) if dsV2 != nil { ln := len(dsV2) - ds = make([]*Detail, 0, ln) + ds = make([]Detail, ln) for i := 0; i < ln; i++ { - var p *Detail - if dsV2[i] != nil { - p = new(Detail) - - if err := p.FromGRPCMessage(dsV2[i]); err != nil { + if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil { return err } } - - ds = append(ds, p) } } diff --git a/status/marshal.go b/status/marshal.go index da6572e5..5e04f24f 100644 --- a/status/marshal.go +++ b/status/marshal.go @@ -88,7 +88,7 @@ func (x *Status) StableMarshal(buf []byte) ([]byte, error) { offset += n 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 { return nil, err } @@ -104,7 +104,7 @@ func (x *Status) StableSize() (size int) { size += protoutil.StringSize(statusMsgFNum, x.msg) for i := range x.details { - size += protoutil.NestedStructureSize(statusDetailsFNum, x.details[i]) + size += protoutil.NestedStructureSize(statusDetailsFNum, &x.details[i]) } return size diff --git a/status/test/generate.go b/status/test/generate.go index 18612122..01df633a 100644 --- a/status/test/generate.go +++ b/status/test/generate.go @@ -17,13 +17,13 @@ func Detail(empty bool) *status.Detail { } // Details returns several status.Detail messages filled with static random values. -func Details(empty bool) []*status.Detail { - var res []*status.Detail +func Details(empty bool) []status.Detail { + var res []status.Detail if !empty { res = append(res, - Detail(false), - Detail(false), + *Detail(false), + *Detail(false), ) } diff --git a/status/types.go b/status/types.go index 6fe233b0..8bcb3af2 100644 --- a/status/types.go +++ b/status/types.go @@ -53,7 +53,7 @@ type Status struct { msg string - details []*Detail + details []Detail } // Code returns code of the Status. @@ -104,7 +104,7 @@ func (x *Status) NumberOfDetails() int { func (x *Status) IterateDetails(f func(*Detail) bool) { if x != nil { for i := range x.details { - if f(x.details[i]) { + if f(&x.details[i]) { break } } @@ -119,14 +119,14 @@ func (x *Status) ResetDetails() { } // AppendDetails appends the list of details to the Status. -func (x *Status) AppendDetails(ds ...*Detail) { +func (x *Status) AppendDetails(ds ...Detail) { if x != nil { x.details = append(x.details, ds...) } } // SetStatusDetails sets Detail list of the Status. -func SetStatusDetails(dst *Status, ds []*Detail) { +func SetStatusDetails(dst *Status, ds []Detail) { dst.ResetDetails() dst.AppendDetails(ds...) }