From 5f2b97a75b5b41c7ed1d69776dc79901ec1be540 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 31 Jul 2023 19:44:52 -0600 Subject: [PATCH] Policy load fix --- policy.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/policy.go b/policy.go index a693cd0..1960861 100644 --- a/policy.go +++ b/policy.go @@ -159,7 +159,7 @@ func (actions NodeActions) MarshalJSON() ([]byte, error) { return json.Marshal(tmp) } -func (actions NodeActions) UnmarshalJSON(data []byte) error { +func (actions *NodeActions) UnmarshalJSON(data []byte) error { tmp := map[string]Actions{} err := json.Unmarshal(data, &tmp) if err != nil { @@ -171,8 +171,8 @@ func (actions NodeActions) UnmarshalJSON(data []byte) error { if err != nil { return err } - - actions[id] = a + ac := *actions + ac[id] = a } return nil @@ -197,7 +197,9 @@ func AllNodesPolicyLoad(init_fn func(Actions)(Policy, error)) func(*Context, []b func PerNodePolicyLoad(init_fn func(NodeActions)(Policy, error)) func(*Context, []byte)(Policy, error) { return func(ctx *Context, data []byte)(Policy, error){ - var policy PerNodePolicy + policy := PerNodePolicy{ + NodeActions: NodeActions{}, + } err := json.Unmarshal(data, &policy) if err != nil { return nil, err