config.go (view raw)
1package main
2
3import (
4 "github.com/BurntSushi/toml"
5 "path/filepath"
6)
7
8type Config struct {
9 FilesDirectory string
10 TemplatesDirectory string
11 Host string
12 HttpsEnabled bool
13 HttpPort int
14 SiteTitle string
15 Debug bool
16 SecretKey string
17 DBFile string
18 LogFile string
19 GeminiCertStore string
20 CookieStoreKey string
21 OkExtensions []string
22 MaxFileBytes int
23 MaxUserBytes int64
24 TLSCertFile string
25 TLSKeyFile string
26 SMTPServer string
27 SMTPUsername string
28 SMTPPassword string
29}
30
31func getConfig(filename string) (Config, error) {
32 var config Config
33 // Attempt to overwrite defaults from file
34 _, err := toml.DecodeFile(filename, &config)
35 if err != nil {
36 return config, err
37 }
38 // Workaround for how some of my path fns are written
39 config.FilesDirectory, _ = filepath.Abs(config.FilesDirectory)
40 return config, nil
41}