mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-05 18:46:16 +00:00
31 lines
630 B
Go
31 lines
630 B
Go
package api
|
|
|
|
import "regexp"
|
|
|
|
type SerializableRegexp struct {
|
|
regexp.Regexp
|
|
}
|
|
|
|
func CompileRegexToSerializableRegexp(expr string) (*SerializableRegexp, error) {
|
|
re, err := regexp.Compile(expr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &SerializableRegexp{*re}, nil
|
|
}
|
|
|
|
// UnmarshalText is by json.Unmarshal.
|
|
func (r *SerializableRegexp) UnmarshalText(text []byte) error {
|
|
rr, err := CompileRegexToSerializableRegexp(string(text))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*r = *rr
|
|
return nil
|
|
}
|
|
|
|
// MarshalText is used by json.Marshal.
|
|
func (r *SerializableRegexp) MarshalText() ([]byte, error) {
|
|
return []byte(r.String()), nil
|
|
}
|