aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYotam Nachum <me@yotam.net>2019-11-22 16:25:47 +0200
committerYotam Nachum <me@yotam.net>2019-11-22 16:25:47 +0200
commitf93ea2f984b018e1b18df841bf53d969c12c383e (patch)
treed6750cd069c33b86429b6b16d8ce206b2a24bc12
parentMove GeminiError and ErrorResponse to go-gemini (diff)
downloadshavit-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.go7
2 files changed, 29 insertions, 1 deletions
diff --git a/config.go b/input.go
index 21dff3d..f532476 100644
--- a/config.go
+++ b/input.go
@@ -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"`
diff --git a/main.go b/main.go
index 79a4758..1b00d45 100644
--- a/main.go
+++ b/main.go
@@ -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)
}