git.alexw.nyc home about git garden
    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
package main

import (
	"path/filepath"

	"github.com/BurntSushi/toml"
)

const HiddenFolder = ".hidden"
const GemlogFolder = "gemlog"

type Config struct {
	FilesDirectory     string
	TemplatesDirectory string
	Host               string
	HttpPort           int
	SiteTitle          string
	Debug              bool
	Hack               bool // No one else uses this code. I will try to box hacks within this bool
	SecretKey          string
	DBFile             string
	AnalyticsDBFile    string
	LogFile            string
	GeminiCertStore    string
	CookieStoreKey     string
	OkExtensions       []string
	MaxFileBytes       int
	MaxFilesPerUser    int
	MaxUserBytes       int64
	SMTPServer         string
	SMTPUsername       string
	SMTPPassword       string
	EnableSFTP         bool
	HostKeyPath        string
}

func getConfig(filename string) (Config, error) {
	var config Config
	// Attempt to overwrite defaults from file
	_, err := toml.DecodeFile(filename, &config)
	if err != nil {
		return config, err
	}
	// Workaround for how some of my path fns are written
	config.FilesDirectory, _ = filepath.Abs(config.FilesDirectory)
	return config, nil
}