-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
125 lines (115 loc) · 2.97 KB
/
config.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
122
123
124
125
package main
// the structure of the config.json file
// where config info is stored
type configData struct {
Port int64
UUID string
Nickname string
BaseURL string `json:"BaseUrl"`
Location string
Writeable bool
NumResizeWorkers int
UploadKeys []string
UploadDirectory string
Neighbors []nodeData
Replication int
MinReplication int
MaxReplication int
GossiperSleep int
VerifierSleep int
ImageMagickConvertPath string
GoMaxProcs int
}
func (c configData) MyNode() nodeData {
n := nodeData{
Nickname: c.Nickname,
UUID: c.UUID,
BaseURL: c.BaseURL,
Location: c.Location,
Writeable: c.Writeable,
}
return n
}
func (c configData) MyConfig() siteConfig {
// todo: defaults should go here
// todo: normalize uploaddirectory trailing slash
numWorkers := c.NumResizeWorkers
if numWorkers < 1 {
// come on! we need at least one
numWorkers = 1
}
replication := c.Replication
if replication < 1 {
replication = 1
}
// these default to replication if not set
minReplication := c.MinReplication
if minReplication < 1 {
minReplication = replication
}
maxReplication := c.MaxReplication
if maxReplication < 1 {
maxReplication = replication
}
gossiperSleep := c.GossiperSleep
if gossiperSleep < 1 {
// default to 60 seconds
gossiperSleep = 60
}
verifierSleep := c.VerifierSleep
if verifierSleep < 1 {
verifierSleep = 300
}
convertPath := c.ImageMagickConvertPath
if convertPath == "" {
convertPath = "/usr/bin/convert"
}
goMaxProcs := c.GoMaxProcs
if goMaxProcs < 1 {
goMaxProcs = 1
}
b := newDiskBackend(c.UploadDirectory)
return siteConfig{
Port: c.Port,
UploadKeys: c.UploadKeys,
UploadDirectory: c.UploadDirectory,
NumResizeWorkers: numWorkers,
Replication: replication,
MinReplication: minReplication,
MaxReplication: maxReplication,
GossiperSleep: gossiperSleep,
VerifierSleep: verifierSleep,
ImageMagickConvertPath: convertPath,
GoMaxProcs: goMaxProcs,
Writeable: c.Writeable,
Backend: b,
}
}
// basically a subset of configData, that is just
// the general administrative stuff
type siteConfig struct {
Port int64
UploadKeys []string
UploadDirectory string
NumResizeWorkers int
Replication int
MinReplication int
MaxReplication int
GossiperSleep int
VerifierSleep int
ImageMagickConvertPath string
GoMaxProcs int
Writeable bool
Backend backend
}
func (s siteConfig) KeyRequired() bool {
return len(s.UploadKeys) > 0
}
func (s siteConfig) ValidKey(key string) bool {
for i := range s.UploadKeys {
if key == s.UploadKeys[i] {
return true
}
}
return false
}