-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathconfig.go
119 lines (100 loc) · 2.18 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
package config
import (
"time"
"github.com/fsnotify/fsnotify"
"github.com/khlieng/dispatch/storage"
"github.com/spf13/viper"
)
type Config struct {
Address string
Port string
Dev bool
Identd bool
HexIP bool
AutoCTCP bool `mapstructure:"auto_ctcp"`
VerifyCertificates bool `mapstructure:"verify_certificates"`
Headers map[string]string
Defaults Defaults
HTTPS HTTPS
LetsEncrypt LetsEncrypt
Auth Auth
DCC DCC
Proxy Proxy
}
type Defaults struct {
Name string
Host string
Port string
Channels []string
ServerPassword string `mapstructure:"server_password"`
SSL bool
ReadOnly bool
ShowDetails bool `mapstructure:"show_details"`
}
type HTTPS struct {
Enabled bool
Port string
Cert string
Key string
HSTS HSTS
}
type HSTS struct {
Enabled bool
MaxAge string `mapstructure:"max_age"`
IncludeSubdomains bool `mapstructure:"include_subdomains"`
Preload bool
}
type LetsEncrypt struct {
Domain string
Email string
}
type Auth struct {
Anonymous bool
Login bool
Registration bool
Providers map[string]Provider
}
type Provider struct {
Key string
Secret string
}
type DCC struct {
Enabled bool
Autoget Autoget
}
type Autoget struct {
Enabled bool
Delete bool
DeleteAfter time.Duration `mapstructure:"delete_after"`
}
type Proxy struct {
Enabled bool
Protocol string
Host string
Port string
Username string
Password string
}
func LoadConfig() (*Config, chan *Config) {
viper.SetConfigName("config")
viper.AddConfigPath(storage.Path.ConfigRoot())
viper.ReadInConfig()
config := &Config{}
viper.Unmarshal(config)
viper.WatchConfig()
configCh := make(chan *Config, 1)
prev := time.Now()
viper.OnConfigChange(func(e fsnotify.Event) {
now := time.Now()
// fsnotify sometimes fires twice
if now.Sub(prev) > time.Second {
config := &Config{}
err := viper.Unmarshal(config)
if err == nil {
configCh <- config
}
prev = now
}
})
return config, configCh
}