-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
66 lines (54 loc) · 1.34 KB
/
structs.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
//go:generate easyjson $GOFILE
package config
type ServerConfig struct {
ServerPublic
}
//easyjson:json
type ServerPublic struct {
MaxSize int64 `json:"maxSize"`
MaxFiles int `json:"maxFiles"`
DefaultCSS string `json:"defaultCSS"`
ImageRootOverride string `json:"imageRootOverride,omitempty"`
}
type AccessMode int
const (
AccessBypass AccessMode = iota - 1
AccessViaBlacklist
AccessViaWhitelist
)
// Some fields will be duplicated in DB because we need to pass them to
// JS client but that doesn't matter.
//easyjson:json
type BoardConfig struct {
BoardPublic
ModOnly bool `json:"modOnly,omitempty"`
AccessMode AccessMode `json:"accessMode,omitempty"`
IncludeAnon bool `json:"includeAnon,omitempty"`
// Pregenerated public JSON.
json []byte
}
//easyjson:json
type BoardPublic struct {
ID string `json:"id"`
Title string `json:"title"`
ReadOnly bool `json:"readOnly,omitempty"`
}
// Implements sort.Interface
//easyjson:json
type BoardConfigs []BoardConfig
func (b BoardConfigs) Len() int {
return len(b)
}
func (b BoardConfigs) Less(i, j int) bool {
return b[i].ID < b[j].ID
}
func (b BoardConfigs) Swap(i, j int) {
b[i], b[j] = b[j], b[i]
}
func (cs *BoardConfigs) TryMarshal() []byte {
data, err := cs.MarshalJSON()
if err != nil {
return []byte("null")
}
return data
}