molly-brown/config.go

44 lines
861 B
Go
Raw Normal View History

2019-11-06 15:08:44 +00:00
package main
import (
"github.com/BurntSushi/toml"
)
type Config struct {
Port int
Hostname string
CertPath string
KeyPath string
DocBase string
HomeDocBase string
LogPath string
CGIPath string
2019-11-06 15:08:44 +00:00
}
func getConfig(filename string) (Config, error) {
var config Config
// Defaults
config.Port = 196
config.Hostname = "localhost"
config.CertPath = "cert.pem"
config.KeyPath = "key.pem"
config.DocBase = "/var/gemini/"
config.HomeDocBase = "users"
config.LogPath = "molly.log"
config.CGIPath = "^/var/gemini/cgi-bin/"
2019-11-06 15:08:44 +00:00
// Return defaults if no filename given
if filename == "" {
return config, nil
}
// Attempt to overwrite defaults from file
_, err := toml.DecodeFile(filename, &config)
if err != nil {
return config, err
}
return config, nil
}