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:
parent
37e015b482
commit
b96cdc79dc
1 changed files with 8 additions and 4 deletions
12
cnf/cnf.go
12
cnf/cnf.go
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue