/
parts.go
202 lines (166 loc) · 4.22 KB
/
parts.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package config
import (
"io"
"os"
"time"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
)
const apiversion = 2
type Server struct {
Address string `toml:"address"`
Port int `toml:"port"`
CertFile string `toml:"cert-file"`
KeyFile string `toml:"key-file"`
PProf bool `toml:"pprof"`
AutoCert struct {
Host string `toml:"host"`
StoragePath string `toml:"storage-path"`
} `toml:"auto-cert"`
}
type Log struct {
Level string `toml:"level"`
File string `toml:"file"`
AccessFile string `toml:"access-file"`
Formatter string `toml:"formatter"`
RepoCallDuration bool `toml:"repo-call-duration"`
Converted struct {
Writer io.Writer
Prefix string
} `toml:"-"`
}
type API struct {
Version int `toml:"version"`
Emulators []string `toml:"emulators"`
Limits struct {
ArticlesPerQuery int `toml:"articles-per-query"`
} `toml:"limits"`
}
type Timeout struct {
Connect string `toml:"connect"`
ReadWrite string `toml:"read-write"`
Converted struct {
Connect time.Duration
ReadWrite time.Duration
} `toml:"-"`
}
type DB struct {
Driver string `toml:"driver"`
Connect string `toml:"connect"`
}
type Auth struct {
Secret string `toml:"secret"`
SessionStoragePath string `toml:"session-storage-path"`
TokenStoragePath string `toml:"token-storage-path"`
}
type Hubbub struct {
CallbackURL string `toml:"callback-url"` // http://www.example.com
From string `toml:"from"`
}
type Popularity struct {
Delay string `toml:"delay"`
Providers []string `toml:"providers"`
Twitter struct {
ConsumerKey string `toml:"consumer-key"`
ConsumerSecret string `toml:"consumer-secret"`
AccessToken string `toml:"access-token"`
AccessTokenSecret string `toml:"access-token-secret"`
} `toml:"twitter"`
Reddit struct {
ID string `toml:"id"`
Secret string `toml:"secret"`
Username string `toml:"username"`
Password string `toml:"password"`
} `toml:"reddit"`
Converted struct {
Delay time.Duration
} `toml:"-"`
}
type FeedParser struct {
Processors []string `toml:"processors"`
ProxyHTTPURLTemplate string `toml:"proxy-http-url-template"`
}
type FeedManager struct {
UpdateInterval string `toml:"update-interval"`
Monitors []string `toml:"monitors"`
Converted struct {
UpdateInterval time.Duration
} `toml:"-"`
}
type Content struct {
Thumbnail struct {
Generator string `toml:"generator"`
Store bool `toml:"store"`
} `toml:"thumbnail"`
Extract struct {
Generator string `toml:"generator"`
ReadabilityKey string `toml:"readability-key"`
} `toml:"extract"`
Search struct {
Provider string `toml:"provider"`
BatchSize int64 `toml:"batch-size"`
BlevePath string `toml:"bleve-path"`
ElasticURL string `toml:"elastic-url"`
} `toml:"search"`
Article struct {
Processors []string `toml:"processors"`
ProxyHTTPURLTemplate string `toml:"proxy-http-url-template"`
} `toml:"article"`
// deprecated
ThumbnailGenerator string `toml:"thumbnail-generator"`
}
type UI struct {
Path string `toml:"path"`
}
type converter interface {
Convert()
}
func (c *API) Convert() {
c.Version = apiversion
}
func (c *Log) Convert() {
if c.File == "-" {
c.Converted.Writer = os.Stderr
} else {
c.Converted.Writer = &lumberjack.Logger{
Filename: c.File,
MaxSize: 20,
MaxBackups: 5,
MaxAge: 28,
}
}
}
func (c *Timeout) Convert() {
if d, err := time.ParseDuration(c.Connect); err == nil {
c.Converted.Connect = d
} else {
c.Converted.Connect = time.Second
}
if d, err := time.ParseDuration(c.ReadWrite); err == nil {
c.Converted.ReadWrite = d
} else {
c.Converted.ReadWrite = time.Second
}
}
func (c *Popularity) Convert() {
if d, err := time.ParseDuration(c.Delay); err == nil {
c.Converted.Delay = d
} else {
c.Converted.Delay = 5 * time.Second
}
}
func (c *FeedManager) Convert() {
if d, err := time.ParseDuration(c.UpdateInterval); err == nil {
c.Converted.UpdateInterval = d
} else {
c.Converted.UpdateInterval = 30 * time.Minute
}
}
func (c *Content) Convert() {
if c.Thumbnail.Generator == "" {
if c.ThumbnailGenerator != "" {
c.Thumbnail.Generator = c.ThumbnailGenerator
} else {
c.Thumbnail.Generator = "description"
}
}
}