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