diff options
author | Yotam Nachum <me@yotam.net> | 2019-11-22 16:25:47 +0200 |
---|---|---|
committer | Yotam Nachum <me@yotam.net> | 2019-11-22 16:25:47 +0200 |
commit | f93ea2f984b018e1b18df841bf53d969c12c383e (patch) | |
tree | d6750cd069c33b86429b6b16d8ce206b2a24bc12 | |
parent | Move GeminiError and ErrorResponse to go-gemini (diff) | |
download | shavit-f93ea2f984b018e1b18df841bf53d969c12c383e.tar.gz shavit-f93ea2f984b018e1b18df841bf53d969c12c383e.zip |
Add an option to specify custom config file
-rw-r--r-- | input.go (renamed from config.go) | 23 | ||||
-rw-r--r-- | main.go | 7 |
2 files changed, 29 insertions, 1 deletions
@@ -1,6 +1,7 @@ package main import ( + "flag" "fmt" "io/ioutil" "path/filepath" @@ -8,6 +9,28 @@ import ( "github.com/BurntSushi/toml" ) +const ( + defaultConfigPath = "/etc/gemini/config.toml" +) + +const ( + configFlagUsage = "A custom path to the server configuration file" +) + +// Flags contain all the flags that were passed to the program +type Flags struct { + ConfigFile string +} + +func getFlags() (Flags, error) { + var f Flags + + flag.StringVar(&f.ConfigFile, "config", defaultConfigPath, configFlagUsage) + flag.Parse() + + return f, nil +} + // Config holds the main configuration data for the server type Config struct { SourceDir string `toml:"source"` @@ -7,7 +7,12 @@ import ( ) func main() { - cfg, err := getConfig("config.toml") + flags, err := getFlags() + if err != nil { + log.Fatal(err) + } + + cfg, err := getConfig(flags.ConfigFile) if err != nil { log.Fatal(err) } |