1
1
Fork 0
mirror of https://tildegit.org/solderpunk/molly-brown synced 2024-06-02 11:36:03 +02:00
molly-brown/config.go

56 lines
1.2 KiB
Go
Raw Normal View History

2019-11-06 16:08:44 +01:00
package main
import (
"github.com/BurntSushi/toml"
)
type Config struct {
Port int
Hostname string
CertPath string
KeyPath string
DocBase string
HomeDocBase string
GeminiExt string
2019-11-06 16:08:44 +01:00
LogPath string
TempRedirects map[string]string
PermRedirects map[string]string
2020-06-08 21:46:39 +02:00
CGIPaths []string
2020-06-04 20:41:40 +02:00
SCGIPaths map[string]string
2019-11-06 16:08:44 +01:00
}
type MollyFile struct {
GeminiExt string
}
2019-11-06 16:08:44 +01:00
func getConfig(filename string) (Config, error) {
var config Config
// Defaults
2020-03-24 22:05:26 +01:00
config.Port = 1965
2019-11-06 16:08:44 +01:00
config.Hostname = "localhost"
config.CertPath = "cert.pem"
config.KeyPath = "key.pem"
config.DocBase = "/var/gemini/"
config.HomeDocBase = "users"
config.GeminiExt = "gmi"
2019-11-06 16:08:44 +01:00
config.LogPath = "molly.log"
config.TempRedirects = make(map[string]string)
config.PermRedirects = make(map[string]string)
2020-06-08 21:46:39 +02:00
config.CGIPaths = make([]string, 0)
2020-06-04 20:41:40 +02:00
config.SCGIPaths = make(map[string]string)
2019-11-06 16:08:44 +01: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
}