-
Notifications
You must be signed in to change notification settings - Fork 2
/
hinter.go
41 lines (32 loc) · 873 Bytes
/
hinter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package util
import (
"github.com/ProtoconNet/mitum2/util"
"github.com/ProtoconNet/mitum2/util/hint"
"github.com/pkg/errors"
)
type BaseHinter struct {
HT hint.Hint `bson:"_hint"` //nolint:tagliatelle //...
}
func NewBaseHinter(ht hint.Hint) BaseHinter {
return BaseHinter{HT: ht}
}
func (ht BaseHinter) Hint() hint.Hint {
return ht.HT
}
func (BaseHinter) SetHint(n hint.Hint) hint.Hinter {
return BaseHinter{HT: n}
}
func (ht BaseHinter) IsValid(expectedType []byte) error {
if err := ht.HT.IsValid(nil); err != nil {
return errors.WithMessage(err, "invalid hint in BaseHinter")
}
if len(expectedType) > 0 {
if t := hint.Type(string(expectedType)); t != ht.HT.Type() {
return util.ErrInvalid.Errorf("Type does not match in BaseHinter, %q != %q", ht.HT.Type(), t)
}
}
return nil
}
func (ht BaseHinter) Bytes() []byte {
return ht.HT.Bytes()
}