1
0
mirror of https://github.com/nxshock/gron.git synced 2024-11-27 03:41:00 +05:00
gron/restartrule.go

37 lines
549 B
Go
Raw Normal View History

2022-03-29 21:38:04 +05:00
package main
import (
"fmt"
)
type RestartRule int
const (
No RestartRule = iota
OnError
)
func (r *RestartRule) MarshalText() (text []byte, err error) {
switch *r {
case No:
return []byte("no"), nil
case OnError:
return []byte("on-error"), nil
}
return nil, fmt.Errorf("unknown restart rule: %v", r)
}
func (r *RestartRule) UnmarshalText(text []byte) error {
switch string(text) {
case "no":
*r = No
return nil
case "on-error":
*r = OnError
return nil
}
return fmt.Errorf("unknown restart rule: %s", string(text))
}