11package settings
22
3- import "fmt"
3+ import (
4+ "errors"
5+ "fmt"
6+ )
47
5- var rules = map [string ]any {
6- "encryption" : map [string ]any {
7- "passphrase" : "" ,
8- },
9- "messages" : map [string ]any {
10- "send_interval_min" : "" ,
11- "send_interval_max" : "" ,
12- "limit_period" : "" ,
13- "limit_value" : "" ,
14- "sim_selection_mode" : "" ,
15- "log_lifetime_days" : "" ,
16- },
17- "ping" : map [string ]any {
18- "interval_seconds" : "" ,
19- },
20- "logs" : map [string ]any {
21- "lifetime_days" : "" ,
22- },
23- "webhooks" : map [string ]any {
24- "internet_required" : "" ,
25- "retry_count" : "" ,
26- "signing_key" : "" ,
27- },
28- }
8+ var (
9+ ErrInvalidField = errors .New ("invalid field" )
10+ )
2911
30- var rulesPublic = map [string ]any {
31- "encryption" : map [string ]any {},
32- "messages" : map [string ]any {
33- "send_interval_min" : "" ,
34- "send_interval_max" : "" ,
35- "limit_period" : "" ,
36- "limit_value" : "" ,
37- "sim_selection_mode" : "" ,
38- "log_lifetime_days" : "" ,
39- },
40- "ping" : map [string ]any {
41- "interval_seconds" : "" ,
42- },
43- "logs" : map [string ]any {
44- "lifetime_days" : "" ,
45- },
46- "webhooks" : map [string ]any {
47- "internet_required" : "" ,
48- "retry_count" : "" ,
49- },
50- }
12+ //nolint:gochecknoglobals // private constants
13+ var (
14+ rules = map [string ]any {
15+ "encryption" : map [string ]any {
16+ "passphrase" : "" ,
17+ },
18+ "messages" : map [string ]any {
19+ "send_interval_min" : "" ,
20+ "send_interval_max" : "" ,
21+ "limit_period" : "" ,
22+ "limit_value" : "" ,
23+ "sim_selection_mode" : "" ,
24+ "log_lifetime_days" : "" ,
25+ },
26+ "ping" : map [string ]any {
27+ "interval_seconds" : "" ,
28+ },
29+ "logs" : map [string ]any {
30+ "lifetime_days" : "" ,
31+ },
32+ "webhooks" : map [string ]any {
33+ "internet_required" : "" ,
34+ "retry_count" : "" ,
35+ "signing_key" : "" ,
36+ },
37+ }
38+
39+ rulesPublic = map [string ]any {
40+ "encryption" : map [string ]any {},
41+ "messages" : map [string ]any {
42+ "send_interval_min" : "" ,
43+ "send_interval_max" : "" ,
44+ "limit_period" : "" ,
45+ "limit_value" : "" ,
46+ "sim_selection_mode" : "" ,
47+ "log_lifetime_days" : "" ,
48+ },
49+ "ping" : map [string ]any {
50+ "interval_seconds" : "" ,
51+ },
52+ "logs" : map [string ]any {
53+ "lifetime_days" : "" ,
54+ },
55+ "webhooks" : map [string ]any {
56+ "internet_required" : "" ,
57+ "retry_count" : "" ,
58+ },
59+ }
60+ )
5161
62+ //nolint:nestif,govet // keep as is
5263func filterMap (m map [string ]any , r map [string ]any ) (map [string ]any , error ) {
5364 var err error
5465
@@ -63,7 +74,7 @@ func filterMap(m map[string]any, r map[string]any) (map[string]any, error) {
6374 } else if m [field ] == nil {
6475 continue
6576 } else {
66- return nil , fmt .Errorf ("the field : '%s' is not a map to dive" , field )
77+ return nil , fmt .Errorf ("%w : '%s' is not a map to dive" , ErrInvalidField , field )
6778 }
6879 } else if _ , ok := rule .(string ); ok {
6980 if _ , ok := m [field ]; ! ok {
@@ -76,6 +87,7 @@ func filterMap(m map[string]any, r map[string]any) (map[string]any, error) {
7687 return result , nil
7788}
7889
90+ //nolint:nestif,gocognit,govet // keep as is
7991func appendMap (m1 , m2 map [string ]any , rules map [string ]any ) (map [string ]any , error ) {
8092 var err error
8193
@@ -98,7 +110,7 @@ func appendMap(m1, m2 map[string]any, rules map[string]any) (map[string]any, err
98110 } else if m2 [field ] == nil {
99111 continue
100112 } else {
101- return nil , fmt .Errorf ("expected field '%s' to be a map, but got %T" , field , m2 [field ])
113+ return nil , fmt .Errorf ("%w: expected field '%s' to be a map, but got %T" , ErrInvalidField , field , m2 [field ])
102114 }
103115 } else if _ , ok := rule .(string ); ok {
104116 if _ , ok := m2 [field ]; ! ok {
0 commit comments