service: implement Raw field setter on RequestMetaHeader struct

After recent changes Raw field is presented in RequestMetaHeader.
There is a need to provide an interface of field getter/setter.

This commit:

  * defines RawHeader interface of raw value container;

  * embeds RawHeader into MetaHeader interface;

  * implements Raw field setter on RequestMetaHeader.
This commit is contained in:
Leonard Lyubich 2020-04-28 15:39:09 +03:00
parent 72a71e6a94
commit 09f8ee52d0
2 changed files with 24 additions and 0 deletions

View file

@ -25,6 +25,9 @@ type (
// VersionHeader allows get or set version of protocol request // VersionHeader allows get or set version of protocol request
VersionHeader VersionHeader
// RawHeader allows to get and set raw option of request
RawHeader
} }
// EpochHeader interface gives possibility to get or set epoch in RPC Requests. // EpochHeader interface gives possibility to get or set epoch in RPC Requests.
@ -39,6 +42,12 @@ type (
SetVersion(uint32) SetVersion(uint32)
} }
// RawHeader is an interface of the container of a boolean Raw value
RawHeader interface {
GetRaw() bool
SetRaw(bool)
}
// TTLCondition is closure, that allows to validate request with ttl. // TTLCondition is closure, that allows to validate request with ttl.
TTLCondition func(ttl uint32) error TTLCondition func(ttl uint32) error
) )
@ -77,6 +86,11 @@ func (m *RequestMetaHeader) SetTTL(v uint32) { m.TTL = v }
// SetEpoch sets Epoch to RequestMetaHeader. // SetEpoch sets Epoch to RequestMetaHeader.
func (m *RequestMetaHeader) SetEpoch(v uint64) { m.Epoch = v } func (m *RequestMetaHeader) SetEpoch(v uint64) { m.Epoch = v }
// SetRaw is a Raw field setter.
func (m *RequestMetaHeader) SetRaw(raw bool) {
m.Raw = raw
}
// ResetMeta returns current value and sets RequestMetaHeader to empty value. // ResetMeta returns current value and sets RequestMetaHeader to empty value.
func (m *RequestMetaHeader) ResetMeta() RequestMetaHeader { func (m *RequestMetaHeader) ResetMeta() RequestMetaHeader {
cp := *m cp := *m

View file

@ -102,3 +102,13 @@ func TestRequestMetaHeader_SetVersion(t *testing.T) {
m.SetVersion(version) m.SetVersion(version)
require.Equal(t, version, m.GetVersion()) require.Equal(t, version, m.GetVersion())
} }
func TestRequestMetaHeader_SetRaw(t *testing.T) {
m := new(RequestMetaHeader)
m.SetRaw(true)
require.True(t, m.GetRaw())
m.SetRaw(false)
require.False(t, m.GetRaw())
}