Skip to content

Instantly share code, notes, and snippets.

@till
Created March 11, 2024 12:43
Show Gist options
  • Save till/11b4264ef751a91b7951546842c1b85a to your computer and use it in GitHub Desktop.
Save till/11b4264ef751a91b7951546842c1b85a to your computer and use it in GitHub Desktop.
diff --git a/main.go b/main.go
index 4bc5c9a..54b5b3f 100644
--- a/main.go
+++ b/main.go
@@ -103,8 +103,8 @@ func main() {
usage()
},
}
- flag.StringVar(&dataDir, "datadir", dataDir, "data directory")
- flag.StringVar(&viewDir, "viewdir", viewDir, "view directory")
+ flag.StringVar(&dataDir, "datadir", getFromEnvOrDefault("DATA_DIR", dataDir), "data directory")
+ flag.StringVar(&viewDir, "viewdir", getFromEnvOrDefault("VIEW_DIR", viewDir), "view directory")
flag.Usage = usage
flag.Parse()
diff --git a/util.go b/util.go
index 7dad7c7..e59b9c9 100644
--- a/util.go
+++ b/util.go
@@ -461,3 +461,11 @@ func openListener() (net.Listener, error) {
listenSocket = listener
return listener, nil
}
+
+func getFromEnvOrDefault(key, value string) string {
+ v, ok := os.LookupEnv(key)
+ if !ok {
+ return value
+ }
+ return v
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment