forked from carl-mastrangelo/pixur
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configuration.go
121 lines (114 loc) · 2.7 KB
/
configuration.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package schema
import (
"reflect"
"time"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
wpb "github.com/golang/protobuf/ptypes/wrappers"
)
var configurationFieldIds []int
func init() {
typ := reflect.TypeOf(Configuration{})
for i := 0; i < typ.NumField(); i++ {
sf := typ.Field(i)
if _, ok := sf.Tag.Lookup("protobuf"); ok {
configurationFieldIds = append(configurationFieldIds, i)
}
}
}
// GetDefaultConfiguration returns a copy of the default configuration. All fields are set.
func GetDefaultConfiguration() *Configuration {
return proto.Clone(defaultConfiguration).(*Configuration)
}
// MergeConfiguration merges two configuration values. Unknown fields are dropped. Unlike
// proto.Merge, only top level fields are considered.
func MergeConfiguration(dst, src *Configuration) {
srcvalp := reflect.ValueOf(src)
if srcvalp.IsNil() {
return
}
dstval, srcval := reflect.Indirect(reflect.ValueOf(dst)), reflect.Indirect(srcvalp)
for _, id := range configurationFieldIds {
dstf, srcf := dstval.Field(id), srcval.Field(id)
if srcf.IsNil() {
continue
}
dstf.Set(srcf)
}
return
}
var defaultConfiguration = &Configuration{
MinCommentLength: &wpb.Int64Value{
Value: 1,
},
MaxCommentLength: &wpb.Int64Value{
Value: 16384,
},
MinIdentLength: &wpb.Int64Value{
Value: 1,
},
MaxIdentLength: &wpb.Int64Value{
Value: 128,
},
MinFileNameLength: &wpb.Int64Value{
Value: int64(len("a.a")),
},
MaxFileNameLength: &wpb.Int64Value{
Value: 255,
},
MinUrlLength: &wpb.Int64Value{
Value: int64(len("http://a/")),
},
MaxUrlLength: &wpb.Int64Value{
Value: 2000,
},
MinTagLength: &wpb.Int64Value{
Value: 1,
},
MaxTagLength: &wpb.Int64Value{
Value: 64,
},
AnonymousCapability: &Configuration_CapabilitySet{
Capability: []User_Capability{
User_PIC_READ,
User_PIC_INDEX,
User_PIC_UPDATE_VIEW_COUNTER,
User_USER_CREATE,
User_USER_READ_PUBLIC,
},
},
NewUserCapability: &Configuration_CapabilitySet{
Capability: []User_Capability{
User_PIC_READ,
User_PIC_INDEX,
User_PIC_UPDATE_VIEW_COUNTER,
User_PIC_TAG_CREATE,
User_PIC_COMMENT_CREATE,
User_PIC_VOTE_CREATE,
User_USER_READ_SELF,
User_USER_READ_PUBLIC,
User_USER_READ_PICS,
User_USER_READ_PIC_COMMENT,
},
},
DefaultFindIndexPics: &wpb.Int64Value{
Value: 12,
},
MaxFindIndexPics: &wpb.Int64Value{
Value: 100,
},
// Ten minutes, with 1 second of leeway
MaxVideoDuration: ptypes.DurationProto(10*time.Minute + 1*time.Second),
EnablePicCommentSelfReply: &wpb.BoolValue{
Value: true,
},
EnablePicCommentSiblingReply: &wpb.BoolValue{
Value: false,
},
DefaultFindUserEvents: &wpb.Int64Value{
Value: 10,
},
MaxFindUserEvents: &wpb.Int64Value{
Value: 100,
},
}