-
-
Notifications
You must be signed in to change notification settings - Fork 589
/
config.go
62 lines (57 loc) · 1.73 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
package config
import (
"path/filepath"
"strings"
"github.com/gotify/configor"
)
// Configuration is stuff that can be configured externally per env variables or config file (config.yml).
type Configuration struct {
Server struct {
ListenAddr string `default:""`
Port int `default:"80"`
SSL struct {
Enabled *bool `default:"false"`
RedirectToHTTPS *bool `default:"true"`
ListenAddr string `default:""`
Port int `default:"443"`
CertFile string `default:""`
CertKey string `default:""`
LetsEncrypt struct {
Enabled *bool `default:"false"`
AcceptTOS *bool `default:"false"`
Cache string `default:"data/certs"`
Hosts []string
}
}
ResponseHeaders map[string]string
Stream struct {
AllowedOrigins []string
}
}
Database struct {
Dialect string `default:"sqlite3"`
Connection string `default:"data/gotify.db"`
}
DefaultUser struct {
Name string `default:"admin"`
Pass string `default:"admin"`
}
PassStrength int `default:"10"`
UploadedImagesDir string `default:"data/images"`
PluginsDir string `default:"data/plugins"`
}
// Get returns the configuration extracted from env variables or config file.
func Get() *Configuration {
conf := new(Configuration)
err := configor.New(&configor.Config{EnvironmentPrefix: "GOTIFY"}).Load(conf, "config.yml", "/etc/gotify/config.yml")
if err != nil {
panic(err)
}
addTrailingSlashToPaths(conf)
return conf
}
func addTrailingSlashToPaths(conf *Configuration) {
if !strings.HasSuffix(conf.UploadedImagesDir, "/") && !strings.HasSuffix(conf.UploadedImagesDir, "\\") {
conf.UploadedImagesDir = conf.UploadedImagesDir + string(filepath.Separator)
}
}