-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecisions.go
44 lines (36 loc) · 899 Bytes
/
decisions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2022 - Offen Authors <hioffen@posteo.de>
// SPDX-License-Identifier: Apache-2.0
package consent
import (
"encoding/json"
"fmt"
)
type domain string
type scope string
type decisions map[domain]map[scope]interface{}
func (d *decisions) update(update *decisions) {
for domain, decisions := range *update {
for s, decision := range decisions {
if (*d)[domain] == nil {
(*d)[domain] = map[scope]interface{}{}
}
(*d)[domain][s] = decision
}
}
}
func (d *decisions) encode() (string, error) {
b, err := json.Marshal(d)
if err != nil {
return "", fmt.Errorf("encode: error marshaling: %w", err)
}
return string(b), nil
}
func parseDecisions(s string) (*decisions, error) {
d := decisions{}
if s != "" {
if err := json.Unmarshal([]byte(s), &d); err != nil {
return nil, fmt.Errorf("parseDecisions: error unmarshaling: %w", err)
}
}
return &d, nil
}