From 03e9a0d5ac5329a6e74f3e3bf34ef590c863a6d3 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 23 Mar 2018 14:44:36 +0200 Subject: Documentation and refactoring --- matrix/pushrules/ruleset.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'matrix/pushrules') diff --git a/matrix/pushrules/ruleset.go b/matrix/pushrules/ruleset.go index b533f94..f3026c8 100644 --- a/matrix/pushrules/ruleset.go +++ b/matrix/pushrules/ruleset.go @@ -39,6 +39,14 @@ type rawPushRuleset struct { Underride PushRuleArray `json:"underride"` } +// UnmarshalJSON parses JSON into this PushRuleset. +// +// For override, sender and underride push rule arrays, the type is added +// to each PushRule and the array is used as-is. +// +// For room and sender push rule arrays, the type is added to each PushRule +// and the array is converted to a map with the rule ID as the key and the +// PushRule as the value. func (rs *PushRuleset) UnmarshalJSON(raw []byte) (err error) { data := rawPushRuleset{} err = json.Unmarshal(raw, &data) @@ -54,6 +62,7 @@ func (rs *PushRuleset) UnmarshalJSON(raw []byte) (err error) { return } +// MarshalJSON is the reverse of UnmarshalJSON() func (rs *PushRuleset) MarshalJSON() ([]byte, error) { data := rawPushRuleset{ Override: rs.Override, -- cgit v1.2.3