diff --git a/internal/rules/rule.go b/internal/rules/rule.go index fffc7adf8..ac39f839f 100644 --- a/internal/rules/rule.go +++ b/internal/rules/rule.go @@ -1,10 +1,5 @@ package rules -import ( - "encoding/json" - "errors" -) - type Access int const ( @@ -21,18 +16,7 @@ type Rule struct { } func (a *Access) UnmarshalJSON(data []byte) error { - var i interface{} - err := json.Unmarshal(data, &i) - if err != nil { - return err - } - - s, ok := i.(string) - if !ok { - return errors.New("Type assertion .(string) failed.") - } - - switch s { + switch string(data) { case "allow": *a = Allow case "deny": @@ -42,3 +26,18 @@ func (a *Access) UnmarshalJSON(data []byte) error { } return nil } + +func (a Access) MarshalJSON() ([]byte, error) { + var str string + + switch a { + case Allow: + str = "allow" + case Deny: + str = "deny" + default: + str = "inherit" + } + + return []byte(`"` + str + `"`), nil +}