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 HttpPort int
16 SiteTitle string
17 Debug bool
18 SecretKey string
19 DBFile string
20 AnalyticsDBFile string
21 LogFile string
22 GeminiCertStore string
23 CookieStoreKey string
24 OkExtensions []string
25 MaxFileBytes int
26 MaxUserBytes int64
27 SMTPServer string
28 SMTPUsername string
29 SMTPPassword string
30}
31
32func getConfig(filename string) (Config, error) {
33 var config Config
34 // Attempt to overwrite defaults from file
35 _, err := toml.DecodeFile(filename, &config)
36 if err != nil {
37 return config, err
38 }
39 // Workaround for how some of my path fns are written
40 config.FilesDirectory, _ = filepath.Abs(config.FilesDirectory)
41 return config, nil
42}