Update serializableRegexp.go

This commit is contained in:
RamiBerm 2021-06-01 14:41:42 +03:00
parent 76bb3db553
commit 1c4588a83c

View File

@ -6,8 +6,6 @@ type SerializableRegexp struct {
regexp.Regexp
}
// CompileRegexToSerializableRegexp wraps the result of the standard library's
// regexp.Compile, for easy (un)marshaling.
func CompileRegexToSerializableRegexp(expr string) (*SerializableRegexp, error) {
re, err := regexp.Compile(expr)
if err != nil {
@ -16,8 +14,7 @@ func CompileRegexToSerializableRegexp(expr string) (*SerializableRegexp, error)
return &SerializableRegexp{*re}, nil
}
// UnmarshalText satisfies the encoding.TextMarshaler interface,
// also used by json.Unmarshal.
// UnmarshalText is by json.Unmarshal.
func (r *SerializableRegexp) UnmarshalText(text []byte) error {
rr, err := CompileRegexToSerializableRegexp(string(text))
if err != nil {
@ -27,8 +24,7 @@ func (r *SerializableRegexp) UnmarshalText(text []byte) error {
return nil
}
// MarshalText satisfies the encoding.TextMarshaler interface,
// also used by json.Marshal.
// MarshalText is used by json.Marshal.
func (r *SerializableRegexp) MarshalText() ([]byte, error) {
return []byte(r.String()), nil
}