-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
87 lines (68 loc) · 1.83 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
package main
import (
"errors"
"github.com/ptt/pttweb/captcha"
"github.com/ptt/pttweb/experiment"
"github.com/ptt/pttweb/extcache"
)
type PttwebConfig struct {
Bind []string
BoarddAddress string
SearchAddress string
MandAddress string
MemcachedAddress string
TemplateDirectory string
StaticPrefix string
SitePrefix string
MemcachedMaxConn int
GAAccount string
GADomain string
EnableOver18Cookie bool
// EnableLinkOriginalInAllPost indicates whether to parse the board name in
// ALLPOST board and link to original posts.
EnableLinkOriginalInAllPost bool
FeedPrefix string
AtomFeedTitleTemplate string
EnablePushStream bool
PushStreamSharedSecret string
PushStreamSubscribeLocation string
RecaptchaSiteKey string
RecaptchaSecret string
CaptchaInsertSecret string
CaptchaExpireSecs int
CaptchaRedisConfig *captcha.RedisConfig
ExtCacheConfig extcache.Config
Experiments Experiments
}
type Experiments struct {
ExtCache experiment.OptIn
}
const (
DefaultBoarddMaxConn = 16
DefaultMemcachedMaxConn = 16
)
func (c *PttwebConfig) CheckAndFillDefaults() error {
if c.BoarddAddress == "" {
return errors.New("boardd address not specified")
}
if c.MemcachedAddress == "" {
return errors.New("memcached address not specified")
}
if c.MemcachedMaxConn <= 0 {
c.MemcachedMaxConn = DefaultMemcachedMaxConn
}
return nil
}
func (c *PttwebConfig) captchaConfig() *captcha.Config {
enabled := c.RecaptchaSiteKey != "" && c.RecaptchaSecret != "" && c.CaptchaRedisConfig != nil
return &captcha.Config{
Enabled: enabled,
InsertSecret: c.CaptchaInsertSecret,
ExpireSecs: c.CaptchaExpireSecs,
Recaptcha: captcha.RecaptchaConfig{
SiteKey: c.RecaptchaSiteKey,
Secret: c.RecaptchaSecret,
},
Redis: *c.CaptchaRedisConfig,
}
}