Implement both TextMarshaler and TextUnmarshaler for codec

If a type only defines one-half of the symmetry (e.g. it implements MarshalJSON() but not UnmarshalJSON() ), then that type doesn't satisfy the codec encoding/decoding check and instead codec will not encode or decode the item using the special interface methods.
This commit is contained in:
Tobie Morgan Hitchcock 2017-11-24 10:54:21 +00:00
parent 37e015b482
commit b96cdc79dc

View file

@ -23,10 +23,6 @@ var Settings *Options
type Kind int type Kind int
func (k Kind) MarshalText() (data []byte, err error) {
return []byte(k.String()), err
}
func (k Kind) String() string { func (k Kind) String() string {
switch k { switch k {
default: default:
@ -42,6 +38,14 @@ func (k Kind) String() string {
} }
} }
func (k Kind) MarshalText() (data []byte, err error) {
return []byte(k.String()), err
}
func (k Kind) UnmarshalText(text []byte) error {
return nil
}
const ( const (
// Root access // Root access
AuthKV Kind = iota AuthKV Kind = iota