[#369] status: Support WRONG_MAGIC_NUMBER code and detail
Define constant for `WrongMagicNumber` local code. Define constant `DetailIDCorrect` for correct magic detail. Add `ResetDetails` and `AppendDetails` method pair. Replace `SetDetails` method with new `SetStatusDetails` function which can be implemented using new methods. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
959d1c8c38
commit
32dd0bb3f9
4 changed files with 27 additions and 4 deletions
8
status/details.go
Normal file
8
status/details.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package status
|
||||||
|
|
||||||
|
// details for WrongMagicNumber code.
|
||||||
|
const (
|
||||||
|
// DetailIDCorrectMagic is an identifier of details with correct network magic
|
||||||
|
// which can be attached to WrongMagicNumber code.
|
||||||
|
DetailIDCorrectMagic = iota
|
||||||
|
)
|
|
@ -57,6 +57,8 @@ const (
|
||||||
const (
|
const (
|
||||||
// Internal is a local Code value for INTERNAL failure status.
|
// Internal is a local Code value for INTERNAL failure status.
|
||||||
Internal Code = iota
|
Internal Code = iota
|
||||||
|
// WrongMagicNumber is a local Code value for WRONG_MAGIC_NUMBER failure status.
|
||||||
|
WrongMagicNumber
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -37,7 +37,7 @@ func Status(empty bool) *status.Status {
|
||||||
if !empty {
|
if !empty {
|
||||||
m.SetCode(765)
|
m.SetCode(765)
|
||||||
m.SetMessage("some string")
|
m.SetMessage("some string")
|
||||||
m.SetDetails(Details(false))
|
status.SetStatusDetails(m, Details(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -106,9 +106,22 @@ func (x *Status) IterateDetails(f func(*Detail) bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDetails sets Detail list of the Status.
|
// ResetDetails empties the detail list.
|
||||||
func (x *Status) SetDetails(v []*Detail) {
|
func (x *Status) ResetDetails() {
|
||||||
if x != nil {
|
if x != nil {
|
||||||
x.details = v
|
x.details = x.details[:0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AppendDetails appends the list of details to the Status.
|
||||||
|
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) {
|
||||||
|
dst.ResetDetails()
|
||||||
|
dst.AppendDetails(ds...)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue